C # Daylight Saving Time

I have events that fire every time I switch to daylight saving time.

I get when spring / fall switches are executed using

TimeZone.CurrentTimeZone.GetDaylightChanges(year)

This returns me 2 days: 1. Run Datetime, which is Spring cutover 3. End Datetime, which is the Fall transition.

Moving Spring works great.

But for the fall, one end of the time I get is 2.00 AM CST. So when I subtract a second, I get 1.59.59 AM CST. Thus, the event will be launched in an hour. I need to set a trigger for 1.59.59 CDT. How do I create this datetime?

+3
source share
1 answer

You want to set it 1 second before the start of the time change. Convert to UTC, then subtract the delta and another second.

DateTime fall; //set to 2:00 AM CST
DaylightTime time; //Filled from your GetDaylightChanges() call.
DateTime fallAdjusted = fall.ToUniversalTime().Subtract(time.Delta).AddSeconds(-1);
+1
source

Source: https://habr.com/ru/post/1791004/


All Articles