You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have recently found out that the time zone information is cached and calls to DateTime.Now and similar APIs use the wrong (old) time zone after the time zone has been changed in the system settings. In order to retrieve the correct local time, it is required to listen to a time zone changed system event and then call TimeZoneInfo.ClearCachedData(); dotnet/runtime#97010
In order to do that, I wanted to implement a method like this:
static NSObject timeZoneObserver;
public static void SetupTimeZoneChangedListener()
{
timeZoneObserver = NSNotificationCenter.DefaultCenter.AddObserver(NSSystemTimeZoneDidChangeNotification, n =>
{
TimeZoneInfo.ClearCachedData();
});
}
However, the NSSystemTimeZoneDidChangeNotification variable is not bound. Neither is NSSystemClockDidChangeNotification
As a workaround, I inspected the variable name in Xcode and I am able to use this workaround:
timeZoneObserver = NSNotificationCenter.DefaultCenter.AddObserver(new NSString("kCFTimeZoneSystemTimeZoneDidChangeNotification"), n =>
{
TimeZoneInfo.ClearCachedData();
});
Environment
.NET 8
The text was updated successfully, but these errors were encountered:
I have recently found out that the time zone information is cached and calls to
DateTime.Now
and similar APIs use the wrong (old) time zone after the time zone has been changed in the system settings. In order to retrieve the correct local time, it is required to listen to a time zone changed system event and then callTimeZoneInfo.ClearCachedData();
dotnet/runtime#97010
In order to do that, I wanted to implement a method like this:
However, the
NSSystemTimeZoneDidChangeNotification
variable is not bound. Neither isNSSystemClockDidChangeNotification
As a workaround, I inspected the variable name in Xcode and I am able to use this workaround:
Environment
.NET 8
The text was updated successfully, but these errors were encountered: