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

Re: Timestamps jump by one hour when switching timezone





On Tue, Nov 2, 2010 at 1:48 PM, Chris Jackson <c.jackson@shadowcat.co.uk> wrote:
Rodolfo Medina wrote:

> Hallo.
>
> Last sunday, in my time zone (Rome), clocks were got back by one hour.  I
> noticed that my Debian Lenny had done so automatically, but files timestamps
> were also took back by one hour, which is not what we want.


File timestamps are (or at least should be) stored in UTC. It's the
display of them that's affected. Setting the TZ variable may help:

export TZ=UTC

Timestamps stored _in_ files (for example log files) are taken from
system time, that stored in /etc/localtime. You might want to set that
to UTC and, where required, alter the displayed time using the TZ
variable, rather than running system time on something with DST, since
it can cause problems with timestamps within log files etc. being
duplicated around the time of the change.

cp /usr/share/zoneinfo/UTC /etc/localtime

Or, you may wish to use a nearer-local non-DST timestamp:

cp /usr/share/zoneinfo/Etc/GMT-1 /etc/localtime

Personally I find using UTC/GMT on all our systems, wherever based, as
system time the simplest, and managing the displayed time using TZ as
applicable. It means to read log files you need to convert, but at least
it's in only one direction, wherever you are.


You could also make a test to see what happen.

touch /tmp/test
ls /tmp/test
date --utc --reference /tmp/test

The output will be similar to:
$ ls -al /tmp/test
-rw-r--r-- root root 0 2010-11-02 14:07 /tmp/test

$date --utc --reference /tmp/test
Tue Nov 2 13:07:23 UTC 2010

I'am in UTC+1 (currently normal time in Europe). If you change you timezone setting, you will see, that the ls output will be show based upon your timezone.
The date command will still show the create time of the file in UTC, and this will not be changed. Timestamps are stored _in_ the file based on UTC like Chris explained.

Mario 

--
http://www.n0r1sk.com


Reply to: