Export (0) Print
Expand All

TimeZoneInfo.FindSystemTimeZoneById Method

Retrieves a TimeZoneInfo object from the registry based on its identifier.

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

Public Shared Function FindSystemTimeZoneById ( _
	id As String _
) As TimeZoneInfo


Type: System.String

The time zone identifier, which corresponds to the Id property.

Return Value

Type: System.TimeZoneInfo
An object whose identifier is the value of the id parameter.


The system does not have enough memory to hold information about the time zone.


The id parameter is Nothing.


The time zone identifier specified by id was not found. This means that a registry key whose name matches id does not exist, or that the key exists but does not contain any time zone data.


The process does not have the permissions required to read from the registry key that contains the time zone information.


The time zone identifier was found, but the registry data is corrupted.

The id parameter must correspond exactly to the time zone's registry key in length, but not in case, for a successful match to occur; that is, the comparison of id with time zone identifiers is case-insensitive. If you want to retrieve time zone objects based on partial matches, you can write custom procedures that work with the read-only collection of TimeZoneInfo objects returned by the GetSystemTimeZones method.

FindSystemTimeZoneById tries to match id to the subkey names of the HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Time Zones branch of the registry under Windows XP and Windows Vista. This branch does not necessarily contain a comprehensive list of time zone identifiers. If required by an application, you can create a particular time zone either by calling one of the overloads of the CreateCustomTimeZone method or by calling FromSerializedString to deserialize a TimeZoneInfo object that represents the required time zone. However, time zones created by these method calls are not included in the registry and cannot be retrieved using the FindSystemTimeZoneById method. These custom time zones can be accessed only through the object reference returned by the CreateCustomTimeZone or FromSerializedString method call.

The following example uses the FindSystemTimeZoneById method to retrieve the Tokyo Standard Time zone. This TimeZoneInfo object is then used to convert the local time to the time in Tokyo and to determine whether it is Tokyo Standard Time or Tokyo Daylight Time.

Module Example
   Public Sub Main()
      ' Get time in local time zone  
      Dim thisTime As Date = Date.Now
      Console.WriteLine("Time in {0} zone: {1}", IIf(TimeZoneInfo.Local.IsDaylightSavingTime(thisTime), 
                        TimeZoneInfo.Local.DaylightName, TimeZoneInfo.Local.StandardName), thisTime)
      Console.WriteLine("   UTC Time: {0}", TimeZoneInfo.ConvertTimeToUtc(thisTime, TimeZoneInfo.Local))
      ' Get Tokyo Standard Time zone 
      Dim tst As TimeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("Tokyo Standard Time")
      Dim tstTime As Date = TimeZoneInfo.ConvertTime(thisTime, TimeZoneInfo.Local, tst)      
      Console.WriteLine("Time in {0} zone: {1}", IIf(tst.IsDaylightSavingTime(tstTime), 
                        tst.DaylightName, tst.StandardName), tstTime)
      Console.WriteLine("   UTC Time: {0}", TimeZoneInfo.ConvertTimeToUtc(tstTime, tst))
   End Sub 
End Module 
' The example displays output like the following when run on a system in the U.S. 
' Pacific Standard Time zone: 
'    Time in Pacific Standard Time zone: 12/6/2013 10:57:51 AM 
'       UTC Time: 12/6/2013 6:57:51 PM 
'    Time in Tokyo Standard Time zone: 12/7/2013 3:57:51 AM 
'       UTC Time: 12/6/2013 6:57:51 PM

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
© 2015 Microsoft