簡體   English   中英

GetUtcOffset 返回某些年份/日期的錯誤偏移量

[英]GetUtcOffset returns the wrong off set for certain years / dates

 var currentServerOffset = TimeZone.CurrentTimeZone.GetUtcOffset(new DateTime(1972, 03, 19, 02, 00, 00);

使用上述返回錯誤的偏移量,但是當您通過 3 月 26 日時,它會得到更正。

似乎這已經關閉了整整一周,在我的測試中,這是在 1972 年和 1973 年參考: https : //greenwichmeantime.com/info/calendars/bst-dates/

我認為這可能與 GetDaylightChanges 在這些年中出錯有關 ref: https ://docs.microsoft.com/en-us/dotnet/api/system.timezone.getdaylightchanges?view=netframework-4.8#remarks

就像我在 1972 年或 1973 年稱此為通過時一樣,開始時間為 7 天。

我如何解決這個問題?

我們無法讓 GetUtcOffset 處理歷史日期。 相反,我們使用了 Noda Time,它應該很簡單:

var dt = Instant.FromUtc(1972, 03, 19, 02, 00, 00);
DateTimeZone zone = DateTimeZoneProviders.Tzdb["Europe/London"];
Offset offset = zone.GetUtcOffset(dt);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM