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

Previous Next

Package: coreutils;

Reported by: Karl Thomas Schmidt <karl.thomas.schmidt <at> googlemail.com>

Date: Sat, 23 Jan 2016 00:34:01 UTC

Severity: normal

Tags: notabug

Done: Assaf Gordon <assafgordon <at> gmail.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 22439 in the body.
You can then email your comments to 22439 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-coreutils <at> gnu.org:
bug#22439; Package coreutils. (Sat, 23 Jan 2016 00:34:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Karl Thomas Schmidt <karl.thomas.schmidt <at> googlemail.com>:
New bug report received and forwarded. Copy sent to bug-coreutils <at> gnu.org. (Sat, 23 Jan 2016 00:34:01 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Karl Thomas Schmidt <karl.thomas.schmidt <at> googlemail.com>
To: bug-coreutils <at> gnu.org
Subject: date -d @0 +%X      returns 01:00:00
Date: Sat, 23 Jan 2016 01:27:49 +0100
Hi <at> all,

tried this with Debian Jessy and openSUSE 13.1

If i specify -d 1970/1/1 it returns proper value of 00:00:00

thx




Information forwarded to bug-coreutils <at> gnu.org:
bug#22439; Package coreutils. (Sat, 23 Jan 2016 07:06:02 GMT) Full text and rfc822 format available.

Message #8 received at 22439 <at> debbugs.gnu.org (full text, mbox):

From: Assaf Gordon <assafgordon <at> gmail.com>
To: Karl Thomas Schmidt <karl.thomas.schmidt <at> googlemail.com>
Cc: 22439 <at> debbugs.gnu.org
Subject: Re: 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 <karl.thomas.schmidt <at> googlemail.com> 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






Added tag(s) notabug. Request was from Assaf Gordon <assafgordon <at> gmail.com> to control <at> debbugs.gnu.org. (Wed, 24 Oct 2018 21:49:03 GMT) Full text and rfc822 format available.

bug closed, send any further explanations to 22439 <at> debbugs.gnu.org and Karl Thomas Schmidt <karl.thomas.schmidt <at> googlemail.com> Request was from Assaf Gordon <assafgordon <at> gmail.com> to control <at> debbugs.gnu.org. (Wed, 24 Oct 2018 21:49:03 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Thu, 22 Nov 2018 12:24:08 GMT) Full text and rfc822 format available.

This bug report was last modified 5 years and 164 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.