System.TimeZoneInfo.Local does not change when changing timezone on iPhone

Issue

I have a Xamarin iOS app which relies on the System.TimeZoneInfo.Local value. When I launch the app and check this property, it seems to be correct (it reflects the timezone as set in my iPhone’s settings). If I background the app and change the timezone in my iPhone settings, then return to the app and look at the System.TimeZoneInfo.Local property, it does not reflect the change in the settings – it still shows the old timezone.

Killing the app completely and re-launching it results in the TimeZoneInfo.Local refreshing to the timezone set in the settings.

Why does this value not change until the app is restarted? Is there a way to fix this?

Solution

It turns out TimeZoneInfo caches timezone info. This cache can be cleared using

System.TimeZoneInfo.ClearCachedData();

Answered By – Victor Chelaru

Leave a Comment