Search code examples
windowsdatetimewinapitimezonelocale

Retrieve DateTime locale offset using WINAPI


The Windows API provides Time Functions. However I could not find a way to given a local DateTime retrieve it's offset from UTC, considering DayLight saving.

E.g: 2015 January 01 (Brasília Time) was on daylight saving period, so instead of -03:00 from UTC, the offset was -02:00.
Now, today (August 02, 2015) we are not in daylight saving, so the offset is again -03:00.

Is there a function (or perhaps another way) to detect that?


Solution

  • One way would you could do it is to use the TzSpecificLocalTimeToSystemTime function for this, since this considers DST.

    Create two SYSTEMTIME structures for midnight on the two dates in question, convert them both to UTC, and then compare the resultant UTC times.