当我在计算机上(在模拟器上测试时)或手机上(直接在手机上测试时)更改时区时,DateTime.ToLocalTime()不会返回更新的结果。
我注册并成功接收UIApplication.Notifications.ObserveSignificantTimeChange. 在其中我调用TimeZoneInfo.ClearCachedData()它允许我检测时区实际上已更改,但这对ToLocalTime(). DateTime我正在转换的绝对是 Utc 类型(例如尝试过)DateTime.UtcNow。
我尝试CultureInfo.CurrentCulture.ClearCachedData()按照此问题中的建议进行调用:SetTimeZoneInformation does not update DateTime.Now for another .NET Application。这只导致应用程序在 为空时崩溃CurrentCulture。
深入挖掘一下执行ToLocalTime(),似乎使用了对象TimeZone.CurrentTimeZone。DateTime.GetNow()仅当和之间的差异时才重置此对象TimeZone.timezone_check。我怀疑在被调用TimeZone.timezone_check时没有更新。TimeZoneInfo.ClearCachedData()
有什么办法可以强制ToLocalTime()考虑时区变化?