In C the function mktime() returns the epoch time according to the local timezone (the input struct is locally formatted).
The function timegm() returns the epoch time according to the UTC time (the input struct is formatted based off of UTC time).
The function localtime_r () takes in an epoch time and returns a local timezone formatted struct.
The function gmtime_r () takes in an epoch time and returns a UTC formatted struct.
I need to find out if a non-local timezone is currently daylight savings time or not, which would work with the localtime_r() function if it were local, but what if it were not local?
The gmtime_r() function always sets the tm_isdst field to zero, which won't work here.
Maybe there's some other function I am not aware of. Not sure.
CodePudding user response:
I need to find out if a non-local timezone is currently daylight savings time or not
- Get the current time as a
time_t
fromtime
. - Set env var
TZ
to the target time zone usingputenv
. - You might have to call
tzset
here? - Use
localtime
to convert thetime_t
into astruct tm
according to the (modified) local time zone. - Check the
tm_isdst
field of thatstruct tm
.