When I change the time zone on my computer (when testing on the simulator) or on the phone (when testing directly on the phone), DateTime.ToLocalTime()
does not return updated results.
I register and successfully receive notification events for UIApplication.Notifications.ObserveSignificantTimeChange
. In it I call TimeZoneInfo.ClearCachedData()
which allows me to detect the time zone has in fact changed but this has no effect on ToLocalTime()
. The DateTime
I am converting is definitely of kind Utc (tried DateTime.UtcNow
for example).
I tried calling CultureInfo.CurrentCulture.ClearCachedData()
as suggested in this question: SetTimeZoneInformation does not update DateTime.Now for another .NET Application. That only causes the application to crash when the CurrentCulture
is nulled.
Digging a bit deeper into the implementation of ToLocalTime()
, it seems to use the object TimeZone.CurrentTimeZone
. This object is reset only when the difference between DateTime.GetNow()
and TimeZone.timezone_check
. I suspect that TimeZone.timezone_check
is not getting updated when TimeZoneInfo.ClearCachedData()
is called.
Is there any way I can force ToLocalTime()
to take into consideration the time zone change?