Check if daylight savings is in effect?

Megaoctane picture Megaoctane · May 19, 2012 · Viewed 54.6k times · Source

How to check if in Denmark daylight time savings has taken effect, if so, then add 1 hour to my data, else not? I have a xml file:

<day = "1"
month = "5"
sunrise ="06:30"
sunset ="21:30"
/>

Answer

Eugene picture Eugene · May 19, 2012

Think you need convert this xml to DateTime and then use TimeZoneInfo class.

If Denmark your local time:

DateTime thisTime = DateTime.Now;
bool isDaylight = TimeZoneInfo.Local.IsDaylightSavingTime(thisTime);

Else you need to get Denmark TimeZone:

DateTime thisTime = DateTime.Now;
// get Denmark Standard Time zone - not sure about that
TimeZoneInfo tst = TimeZoneInfo.FindSystemTimeZoneById("Denmark Standard Time");
bool isDaylight = tst.IsDaylightSavingTime(thisTime);