Commands for interchange of date, time, and Unix timestamps in Linux Command lines
At work, you often need to get the current Unix timestamp or convert the given timestamp to a date format that we can recognize, on the linux Command Line terminal, you can easily solve the problem by using several commands.
1. convert a date to a Unix Timestamp
(1) present the current time in Unix timestamp:
Date + % s
The output is as follows:
1361542433
(2) convert the specified date to the Unix timestamp:
Date-d '2017-2-22 '+ % s
The output is as follows:
1361542440
2. Convert Unix timestamp to datetime
(1) do not specify the date and time format:
Date-d @ 1361542596
The output is as follows:
Fri Feb 22 12 22:16:36 CST 2013
(2) Date Format Conversion:
Date-d @ 1361542596 + "% Y-% m-% d % H: % M: % S"
The output is as follows:
2013-02-22 22:16:36