The Date Command and Seconds Since 1970-01-01
The man page for the date command says that the %s option will give “seconds since 1970-01-01 00:00:00 UTC“. I had expected that everything that date did would give output in my time zone unless I requested otherwise.. But it seems that in this case the result is in UTC, and the same seems to be also true for most programs that log dates with the number of seconds.
In a quick google search for how to use a shell script to convert from the number of seconds since 1970-01-01 00:00:00 UTC to a more human readable format the only remotely useful result I found was the command date -d "1970-01-01 1212642879 sec", which in my timezone gives an error of ten hours (at the moment - it would give eleven hours in summer). The correct method is date -d "1970-01-01 1212642879 sec utc", you can verify this with the command date -d "1970-01-01 $(date +%s) sec utc" (which should give the same result as date).


remember to use “” instead of “” when typing the command.
June 5th, 2008 at 4:04 pm[...] This entry was posted on Thursday, June 5th, 2008 at 4:22 pm, for similar articles see the category Networking. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site. « The Date Command and Seconds Since 1970-01-01 [...]
June 5th, 2008 at 4:22 pmHi,
take a look into info pages for GNU date
date -d @1212642879
date -d “@$(date +%s)”
Regards
June 5th, 2008 at 4:28 pm–
Zito
Ruben: Unfortunately your comment was munged in exactly the same way as my post. I believe that I have now corrected the error you referr to.
Vaclav: Thanks for that! It’s a pity it’s not in the man page.
June 5th, 2008 at 4:35 pmI think it is a trifle odd to think of the seconds output as being in a time zone at all. It is the
June 5th, 2008 at 4:46 pmnumber of seconds since a particular point in time (the Unix epoch). When that point in time is represented in UTC that representation is 1970-01-01 00:00:00.
Here’s a command to try:
date -d “2009-02-13 23:31:30 UTC” +%s
Not that far away either.
June 6th, 2008 at 4:52 am