Check if daylight savings is in effect?

前端 未结 8 1790
悲哀的现实
悲哀的现实 2020-12-29 02:14

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:



        
8条回答
  •  庸人自扰
    2020-12-29 03:05

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

提交回复
热议问题