How to represent the current UK time?

前端 未结 5 1854
暗喜
暗喜 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:43

    I think you're converting to UTC (instead of UK) time. Since there is still summer time in Central Europe (event if the temperatures say otherwise), the difference is +2 hours until October, 31st.

    If you know that you're converting from Germany to UK (i.e. CEST to BST in summer and CET to GMT in winter), why you don't just subtract 1 hour?

    If you want the time zone information for UK, you can construct it using

    var britishZone = TimeZoneInfo.FindSystemTimeZoneById("GMT Standard Time");
    

    Then you could convert the date using

    var newDate = TimeZoneInfo.ConvertTime(serverDate, TimeZoneInfo.Local, britishZone);
    

提交回复
热议问题