Jay Taylor's notes
back to listing indexgeeks|programmers — How to convert from/to epoch dates | Life..., and technology
[web search]geeks|programmers — How to convert from/to epoch dates
If you use a Unix system(BSD,Linux,etc.), sometimes you’ll have log files that don’t create the timestamp in regular format such as Apr. 25, 2011 1:10pm but instead it saves the date as the number of seconds since midnight of January 1, 1970 (the date chosen after the fact for the beginning of the Unix epoch).
How to convert from epoch seconds to regular date?
If you’re on any of the BSD systems (such as Mac OS X or FreeBSD), run “date -r SECONDS” from a Terminal:
$ date -r 1302972510
Sat Apr 16 10:48:30 MDT 2011
If you’re using Linux, run “date -d @SECONDS” from a terminal — here’s an example:
$ date -d @1302972510
Sat Apr 16 10:48:30 MDT 2011
Convert from regular date to seconds?
On Linux, here’s an example:
$ date -d “Apr 25, 2011 12:12:12″ +%s
1303755132
For the BSD’s/OS X, here’s an example:
$ date -j -f ‘%Y-%m-%d %H:%M:%S’ ’2011-04-25 12:12:12′ +%s
1303755132
(I’ve had to look this up enough times over the years that I thought i’d finally publish it!