TimeZoneInfo.ClearCachedData Method


Clears cached time zone data.

 static void ClearCachedData();
public static void ClearCachedData ();
static member ClearCachedData : unit -> unit
Public Shared Sub ClearCachedData ()


Cached time zone data includes data on the local time zone and the Coordinated Universal Time (UTC) zone.

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);
Dim cst As TimeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time")
Dim local As TimeZoneInfo = TimeZoneInfo.Local
Console.WriteLine(TimeZoneInfo.ConvertTime(Date.Now, local, cst))

   Console.WriteLine(TimeZoneInfo.ConvertTime(Date.Now, local, cst))
Catch e As ArgumentException
   Console.WriteLine(e.GetType().Name & vbCrLf & "   " & e.Message)
End Try

Applies to