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


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


Leave A Reply - 3 Replies
bob 2005-02-10 11:23am - No Email - Logged IP:

The command for the second example could be simplified to:

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

jason 2006-02-18 04:45am - jason@... - Logged IP:

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

Peter 2011-07-26 11:59pm - No Email - Logged IP:

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