Linux date

The linux date command is unixtime aware. You can have it output the seconds since the epoch with a simple command. Date followed by a plus to show it's a format, and the %s to show the seconds.

date +%s

However if you want to go the OTHER way it's really freaking ugly. I can't believe there isn't an easier way to do that!

date -d @371407800

or

date -d '1970-01-01 UTC +1097575205 seconds'

Easy.

Leave A Reply - 3 Replies
Replies
February 10th 2005 - bob

The command for the second example could be simplified to:

date -d "1970-01-01 +date +%s seconds"

February 18th 2006 - jason

Thank you for a super simple example on how to get the seconds since 1970!

July 26th 2011 - Peter

If you leave out the UTC you get the wrong time if you are in a different time zone. So date -d "1970-01-01 UTC + $(date +%s) seconds" is correct as it will give you Wed Jul 27 08:57:13 CEST 2011 if your time zone is CEST whereas leaving out the UTC will give you Wed Jul 27 07:57:13 CEST 2011 which is wrong!

All content licensed under the Creative Commons License