[Top][All Lists]

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

Re: error in hours given by date -d @anyNumber

From: Greg Wooledge
Subject: Re: error in hours given by date -d @anyNumber
Date: Mon, 17 Jan 2022 16:01:28 -0500

On Mon, Jan 17, 2022 at 09:10:59PM +0100, Girod Valentin wrote:
> Description:
>     when using date -d @customNumber +%H,
>     it returns 1 more hour that the expected hour.

First thing to note: date(1) is not part of bash.  It's part of GNU
coreutils, if you're on a GNU/Linux system.  You're reporting this in
the wrong place.

> Repeat-By:
>     date -d @0 +%T
>     returns: 01:00:00 (WHAT THE FUCK)
>     excpected output: 00:00:00

This result depends on your time zone.  @0 represents the Unix epoch,
which is 00:00:00 Januay 1, 1970 UTC.  If you're in UTC, then you'll
get the result you expect.

unicorn:~$ date -d @0 +%T
unicorn:~$ date -u -d @0 +%T

The -u option forces the UTC time zone.  You could do the same thing with
the TZ variable.

>     date -d @18130 +%T
>     returns: 06:02:10
>     expected output: 05:02:10

You're apparently in a time zone that's 1 hour ahead of UTC.  I think
a large chunk of Europe is in that time zone.

unicorn:~$ date -d @18130 +%T
unicorn:~$ TZ=UTC date -d @18130 +%T
unicorn:~$ TZ=Europe/Paris date -d @18130 +%T

reply via email to

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