May 2007
Beginner
628 pages
15h 46m
English
You need to convert Epoch seconds to a human-readable date and time.
Use the GNU date command with your desired format from Formatting Dates for Display:
EPOCH='1131173989' $ date -d "1970-01-01 UTC $EPOCH seconds" +"%Y-%m-%d %T %z" 2005-11-05 01:59:49 -0500 $ date --utc --date "1970-01-01 $EPOCH seconds" +"%Y-%m-%d %T %z" 2005-11-05 06:59:49 +0000
Since Epoch seconds are simply the number of seconds since the Epoch (which is Midnight on January 1, 1970, also known as 1970-01-01T00:00:00), this command starts at the Epoch, adds the Epoch seconds, and displays the date and time as you wish.
If you don’t have GNU date on your system you can try one of these Perl one-liners:
EPOCH='1131173989'
$ perl -e "print scalar(gmtime($EPOCH)), qq(\n);" # UTC
Sat Nov 5 06:59:49 2005
$ perl -e "print scalar(localtime($EPOCH)), qq(\n);" # Your local time
Sat Nov 5 01:59:49 2005
$ perl -e "use POSIX qw(strftime); print strftime('%Y-%m-%d %H:%M:%S',
localtime($EPOCH)), qq(\n);"
2005-11-05 01:59:49man date
“Date and Time String Formatting with strftime” in Appendix A
Read now
Unlock full access