How do I convert an epoch timestamp to a human readable format on the cli?
On *BSD:
date -r 1234567890
On Linux (specifically, with GNU coreutils ≥5.3):
date -d @1234567890
With older versions of GNU date, you can calculate the relative difference to the UTC epoch:
date -d '1970-01-01 UTC + 1234567890 seconds'
If you need portability, you're out of luck. The only time you can format with a POSIX shell command (without doing the calculation yourself) line is the current time. In practice, Perl is often available:
perl -le 'print scalar localtime $ARGV[0]' 1234567890
date -d @1190000000
Replace 1190000000 with your epoch
If your epoch time is in milliseconds instead of seconds, remove the last three digits before passing it to date -d
:
$ date -d @1455086371603
Tue Nov 7 02:46:43 PST 48079 #Incorrect
This gives incorrect data. Remove the last three digits.
$ date -d @1455086371
Tue Feb 9 22:39:31 PST 2016 #Correct after removing the last three digits. You may remove and round off the last digit too.