[Linux] conversion between the date command Timestamp and time
Most of the time we view the data in the database, or some data in other systems needs to be queried using timestamps, or the query results are timestamps. In addition, you must enter a timestamp for the query condition. My previous method was to use an online tool, and then I used a mac. I thought it would be nice to use a command line to solve the problem, you don't need to open a browser every time (in fact, it is also troublesome to be unfamiliar with the command)
Here is the operation in mac, mainly using the date command. For more usage, use the man command to view
String format time TO Timestamp
We know that the date command can directly convert the current time to the timestamp.
# date +%s1436781527
Then, we will convert the defined time to the timestamp.
# date -j -f "%Y-%m-%d %H:%M:%S" "2015-07-13 18:02:00" "+%s"1436781720
In fact, this is a little complicated.
Timestamp to time
However, it is easy to convert the timestamp into a readable time format. mac and centos are slightly different.
Mac
Date-r1436781720 Monday July 13, 2015 seconds CST
On centos
$ Date-d @ 14367817202015 Monday, January 1, July 13 18:02:00 CST
These two commands are really easy to remember.