How to determine if daylight saving time is active in C?

I have a cross-platform C application. In this program, I need to write a function that determines whether a given date is DST or not.
Actually, I am trying to find the DST-DST start dates in pure C. Is there an easy and standard way to do this?

+4
source share
2 answers

time.h provides tm structs with the tm_isdst flag. Use time to get the current time, localtime to get the tm structure with the time adjusted to the current language, and read the tm_isdst flag.

From the man page:

 tm_isdst A flag that indicates whether daylight saving time is in effect at the time described. The value is positive if daylight saving time is in effect, zero if it is not, and negative if the information is not available. 
+4
source

The implementation does not suggest that tm_isdst is always 0. It must provide the correct data. If the implementation cannot provide tm_isdst, which is consistent with the rules established in the country, then it must set tm_isdst to a negative value, as specified in 7.23.1 / 4 in the same standard .

-1
source

All Articles