Check if daylight savings is in effect?

前端 未结 8 1786
悲哀的现实
悲哀的现实 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:18

    this is my short solution which can be using in all timezones:

    DateTime utcTime = DateTime.Parse("30.10.2018 18:21:34")
    DateTime localtime = ConvertUTCToLocalTime(utcTime);
    
    
    public static DateTime ConvertUTCToLocalTime(DateTime UTCTime)
    {
        var localZone = TimeZone.CurrentTimeZone;
        var offset = localZone.GetUtcOffset(UTCTime);
        var localTime = UTCTime.AddHours(offset.Hours);
        return localTime;
    }
    

提交回复
热议问题