How to represent the current UK time?

前端 未结 5 1849
暗喜
暗喜 2021-01-02 02:37

I\'m facing an issue while converting dates between my server and client where both is running in Germany. The Regional settings on the client machines could be set to both

5条回答
  •  执笔经年
    2021-01-02 03:29

    This is what I do:

        var BritishZone = TimeZoneInfo.FindSystemTimeZoneById("GMT Standard Time");
    
        DateTime dt = DateTime.SpecifyKind(DateTime.UtcNow, DateTimeKind.Unspecified);
    
        DateTimeInBritishLocal = TimeZoneInfo.ConvertTime(dt, TimeZoneInfo.Local, BritishZone);
    

    I needed to add the SpecifyKind part or the ConvertTime throws an exception

提交回复
热议问题