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).

Tags: ,

6 thoughts on “The Date Command and Seconds Since 1970-01-01”

  1. Ruben says:

    remember to use “” instead of “” when typing the command.

  2. Pingback: BIND Stats | etbe
  3. Vaclav Ovsik says:

    take a look into info pages for GNU date

    date -d @1212642879
    date -d “@$(date +%s)”



  4. etbe says:

    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.

  5. Bill Hay says:

    I think it is a trifle odd to think of the seconds output as being in a time zone at all. It is the
    number 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.

  6. Joe Buck says:

    Here’s a command to try:

    date -d “2009-02-13 23:31:30 UTC” +%s

    Not that far away either.

Comments are closed.