.Net DateTime with local time and DST

后端 未结 2 1373
慢半拍i
慢半拍i 2021-01-13 17:48

I\'m afraid I don\'t really understand how .Net\'s DateTime class handles local timestamps (I live in Germany, so my locale is de_DE). Perhaps someone can enlig

2条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-13 18:23

    Yes, the DateTime type in .NET is major mess, as you can observe because it doesn't support the concepts of time-zones, multiple calendars and many other useful concepts such as intervals etc.

    A little better is the DateTimeOffset type which adds time-zone offset information. The DateTimeOffset will allow you to more accurately represent the times you show in your question and comparisons will take the timezone offset into account. But this type is not perfect either. It still does not support true time zone information, only the offset. So it is not possible to perform complex DST calculations or to support advanced calendars.

    For a much more thorough solution you can use NodaTime

提交回复
热议问题