ClearCachedData Method

TimeZoneInfo.ClearCachedData Method ()


Clears cached time zone data.

Namespace:   System
Assembly:  mscorlib (in mscorlib.dll)

public static void ClearCachedData()

Cached time zone data includes data on the local time zone, the Coordinated Universal Time (UTC) zone, and any time zones that are retrieved by using methods such as FindSystemTimeZoneById and GetSystemTimeZones.

You might call the ClearCachedData method to reduce the memory devoted to the application's cache of time zone information or to reflect the fact that the local system's time zone has changed.

Storing references to the local and UTC time zones is not recommended. After the call to the ClearCachedData method, these object variables will be undefined TimeZoneInfo objects that are no longer references to TimeZoneInfo.Local or TimeZoneInfo.Utc. For example, in the following code, the second call to the TimeZoneInfo.ConvertTime(DateTime, TimeZoneInfo, TimeZoneInfo) method throws an ArgumentException because the local variable is no longer considered equal to TimeZoneInfo.Local.

TimeZoneInfo cst = TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time");
TimeZoneInfo local = TimeZoneInfo.Local;
Console.WriteLine(TimeZoneInfo.ConvertTime(DateTime.Now, local, cst));

   Console.WriteLine(TimeZoneInfo.ConvertTime(DateTime.Now, local, cst));
catch (ArgumentException e)
   Console.WriteLine(e.GetType().Name + "\n   " + e.Message);

.NET Framework
Available since 3.5
Return to top
© 2015 Microsoft