Current Time of Timezone

前端 未结 3 1782
情书的邮戳
情书的邮戳 2021-01-18 08:57

I have different timezones and their GMT and DST. Example:

TimeZoneId        |   GMT offset  |   DST offset  
              


        
3条回答
  •  囚心锁ツ
    2021-01-18 09:15

    private static ReadOnlyCollection _timeZones = TimeZoneInfo.GetSystemTimeZones();
    
    public static DateTime ToUsersTime(this DateTime utcDate, int timeZoneId)
    {
        return TimeZoneInfo.ConvertTimeFromUtc(utcDate, timeZones[timeZoneId]);
    }
    

    An example of converting a UTC date to a user's date using the TimeZoneInfo class (.NET 3.5+).

提交回复
热议问题