PDA

View Full Version : inside localtime() - wondering how to easily extract timezone difference



jamadagni
9th January 2006, 14:51
I quote from man localtime:

The ctime(), gmtime() and localtime() functions all take an argument of data type time_t which represents calendar time. When interpreted as an absolute time value, it represents the number of seconds elapsed since 00:00:00 on January 1, 1970, Coordinated Universal Time (UTC).
Now I get this time_t value using time(NULL), and pass a pointer to that value to localtime() to get the local time as a struct tm. I wonder how localtime finds out the time zone value which is not a part of the time_t value (as far as I can make out from the man page.

Any hints as to this would be appreciated. Otherwise I have to do some circus with finding out the difference between the values returned by localtime and gmtime.

yop
9th January 2006, 15:01
Quoting from man 3p localtime

The localtime() function shall convert the time in seconds since the Epoch pointed to by timer into a broken-down time, expressed as a local time. The function corrects for the timezone and any seasonal time adjustments. Local timezone information is used as though localtime() calls tzset().

So man tzset has the answers ;) (if I understood your question right)

jamadagni
9th January 2006, 15:49
Quoting from man 3p localtime
So man tzset has the answers ;) (if I understood your question right)
Well ya I forgot to mention that I have read through tzset - but it appears to be a UNIX-specific thing. How would then the localtime() function compile/work on DOS/Windows?

wysota
9th January 2006, 16:41
Well ya I forgot to mention that I have read through tzset - but it appears to be a UNIX-specific thing. How would then the localtime() function compile/work on DOS/Windows?

Does it matter? The most important part is that it works (if it works, because localtime() is not an ANSI C function, so I guess non-posix Windows may not have it), right? Let's leave libc programming to libc programmers.

yop
9th January 2006, 21:30
http://cygwin.com/cygwin-api/cygwin-api.html (but be warned the water is getting deeper ;))

jamadagni
10th January 2006, 04:41
localtime() is not an ANSI C function
Of course it's an ANSI C function - it is listed and described by K&R in their ANSI C book.

wysota
10th January 2006, 14:07
"man localtime" gives this as compliance standards:


SVID 3, POSIX, BSD 4.3, ISO 9899