Search code examples
c#windows-phone-7datetimedst

Check if daylight savings is in effect?


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"
/>

Solution

  • 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);