I have a C application running on cross platforms. In this program, I need to write a function which determines if the given date is DST or not.
Actually, i try to find DST begin-DST end dates in pure C. Is there any simple and standard way to do this?
time.h
provides tm
structs with a tm_isdst
flag. Use time
to get the current time, localtime
to get a tm
struct with the time adjusted to the current locale and read the tm_isdst
flag.
From the manpage:
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.
The code is:
time_t rawtime;
struct tm timeinfo; // get date and time info
time(&rawtime);
localtime_s(&timeinfo, &rawtime);
int isdaylighttime = timeinfo.tm_isdst;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With