I'm experiencing a bizarre issue where my system clock knows that it's daylight savings time, but glibc seems not to. This is an up-to-date Ubuntu installation, and I have checked /etc/localtime and it has the correct changeover time for last week's switch to DST.
The current correct timezone for me is Pacific Daylight Time (UTC-7). When I ask my system what time zone I'm in, 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 output is, incorrectly:
28800
Which corresponds to UTC-8, or Pacific Standard Time. (And no, TZ is not set in my environment)
I thought glibc and the date program would get their time zone information from the same source, but apparently either they don't or I'm misunderstanding how the glibc timezone global works.
The basic questions are then:
- Why are these two outputs different
- How can I reliably detect the system UTC offset from a C program?