bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#22439: date -d @0 +%X returns 01:00:00


From: Assaf Gordon
Subject: bug#22439: date -d @0 +%X returns 01:00:00
Date: Sat, 23 Jan 2016 02:04:58 -0500

tag 22439 notabug
close 22439
stop

Hello,

> On Jan 22, 2016, at 19:27, Karl Thomas Schmidt <address@hidden> wrote:
> 
> If i specify -d 1970/1/1 it returns proper value of 00:00:00

This is not a bug, but simply a side-effect of ignoring your local timezone.

Using '-d @0' syntax specifies seconds-since-epoch in UTC timezone, regardless 
of your computer's timezone.
But when the date is printed, it is converted to your computer's timezone - 
hence the offset.

Examples:

    (on my computer, in which timezone = EST,-05:00)
    $ date -d '@0'
    Wed Dec 31 19:00:00 EST 1969

    $ TZ=UTC date -d '@0'
    Thu Jan  1 00:00:00 UTC 1970

    $ TZ=Asia/Tokyo date -d '@0'
    Thu Jan  1 09:00:00 JST 1970

Thus, when using '-d @0', it is useful to add the '-u' option (print in UTC):

    $ date -u -d '@0'
    Thu Jan  1 00:00:00 UTC 1970
    $ date -u -d '@0' +%X
    00:00:00

When using an explicit date (but without explicit time zone), the assumed time 
zone is your local computer's.
Thus, specifying  '-d 1970/1/1' means midnight of 1-Jan-1970 in *your local 
timezone*. Then this time is printed in your local time zone, and the printed 
time stays at midnight:

    $ date -d '1970/1/1'
    Thu Jan  1 00:00:00 EST 1970


I'm therefore marking this bug as closed, but discussion can continue by 
replying to this thread.

regards,
  - assaf







reply via email to

[Prev in Thread] Current Thread [Next in Thread]