I am experiencing a strange problem when my system clock knows that it is summer time, but glibc does not seem to be so. This is a modern Ubuntu installation, and I checked / etc / localtime, and it has the correct switch time to switch to DST last week.
The current correct time zone for me is Pacific Daylight Time (UTC-7). When I ask my system in which time zone I enter, it tells me correctly:
$ date +%z -0700
But when I run the following program:
#include <time.h> #include <stdio.h> int main() { tzset(); printf("%lu\n", timezone); return 0; }
The result is incorrect:
28800
Which corresponds to UTC-8, or Pacific Standard Time. (And no, TZ is not installed in my environment)
I thought that glibc and the date program would get timezone information from the same source, but apparently they either donβt do it, or I donβt understand how the glibc global timezone works.
Main questions:
- Why are these two outputs different from each other?
- How can I reliably determine the offset of a UTC system from program C?
c timezone glibc
Tyler mchenry
source share