Search code examples
c#win-universal-appwindows-10-universal

TimeZoneInfo.ClearCachedData not in Universal Windows


This is a follow up question to DateTime.Now vs system time

In normal .NET TimeZoneInfo.ClearCachedData() is available to sync the application the system timezone.

In Universal Windows version of TimeZoneInfo this method is not present.

Can I somehow sync the timezone info?


Solution

  • Solution 1

    using System.Reflection;
    
    MethodInfo clearCachedData = typeof(TimeZoneInfo).GetMethod("ClearCachedData", 
       BindingFlags.NonPublic | BindingFlags.Static);
    if (clearCachedData != null)
    {
        clearCachedData.Invoke(null, null);
    }
    

    Tested on:

    • Device Model: Raspberry Pi 3
    • OS Version: 10.0.14393.0

    Solution 2

    How to clear TimeZoneInfo cache in WinRT?