Jan 1st 1970! Unix time conversions

If you store dates in MySQL in unix time format, its nice to be able to quickly convert it back!

In Linux, the terminal command can either be:

$ date -d @1344262406
Mon Aug  6 15:13:26 BST 2012

or:

$ date -u --date="1970-01-01 1344262406 sec GMT"
Mon Aug  6 14:13:26 UTC 2012

Guess which one I prefer? Note the timezone differences.

On a Mac (or any other Unix), you can try this:

$ date -r 1282368345
Sat Aug 21 07:25:45 CEST 2010
$ date -r 1282368345 +%Y-%m-%d
2010-08-21

Leave a comment