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

Re: How/where does the kernal compute local time



> Dos anyone know where or how in the kernal does the machine time gets
> converted to local time? I'm most curious as to how DST gets
> figured.
> For example, the machine runs on UTC, but I can set my TZ=EST.
>
> When I get my local time, it tells me if I'm in DST or not (the kernal
> must
> also be updating my local time by 1 hour if neccessary to). 

The kernel runs on GMT, or UTC, whichever you want to call it. Commands
like 'date' *display* the time in the local time zone, but the clock
they are reading is always in in GMT.

I think there is some low-level C function (maybe localtime() ?) that
consults various sources (environment variables, locale config files)
in order to determine how you would like the time presented to you.
The 'date' command almost certainly uses this.

As you saw, TZ affects this:

	dione$ date
	Fri Mar 26 12:12:00 CET 2004
	dione$ TZ=GMT date
	Fri Mar 26 11:12:03 GMT 2004
	dione$ 

But normally you want to rely only on the config files to determine
how the time is presented to you. If you want to change these then
run 'tzconfig' as root. If you want to understand what it does then
just use a text editor on /usr/sbin/tzconfig (preferrably not as
root).

Regarding daylight saving time, again, the kernel does *not* change
the clock (if you're dual-booting with some MS-ish OS then this *it*
may change the clock though!). 

Again, the localtime() function knows how to determine when it should
start making adjustments in the way that it presents the time to you.

So just to repeat: the kernel does not convert GMT to local time. It
*only* uses GMT time. It is the *presentation* made by each and
every time-using command that does the conversion of time zone and
daylight saving time *for presentation purposes only*.

Alexis

http://dione.no-ip.org/~alexis/



Reply to: