c - How to known which time zone the system is using -
i'm doing code need known time zone active in system (i'm working on linux so):
my first aproach check
tz
enviroment var,it's empty unless set (for instance calling tzset)after try
extern long timezone
(time.h) variable 0.finally calculate difference of timezone , utc+0 don't real timezone because don't known if daylight saving apply
i'm pretty sure there easy (and consistent) way achieve this. i'm looking "europe/paris" or "utc+2" or that
any appreciated!
as starting point, suggest this:
#include <stdio.h> #include <stdlib.h> #include <time.h> int main(void) { char str[64]; time_t timer; struct tm * ptm; timer = time(null); ptm = localtime(&timer); strftime(str, sizeof(str), "%z", ptm); printf("tz: %s\n", str); return(0); }
Comments
Post a Comment