TimeZoneInfo.Local Property

Definition

Gets a TimeZoneInfo object that represents the local time zone.

public:
 static property TimeZoneInfo ^ Local { TimeZoneInfo ^ get(); };
public static TimeZoneInfo Local { get; }
public static TimeZoneInfo Local { [System.Security.SecurityCritical] get; }
static member Local : TimeZoneInfo
[<get: System.Security.SecurityCritical>]
static member Local : TimeZoneInfo
Public Shared ReadOnly Property Local As TimeZoneInfo

Property Value

An object that represents the local time zone.

Attributes

Examples

The following example retrieves a TimeZoneInfo object that represents the local time zone and outputs its display name, standard time name, and daylight saving time name.

using System;

public class Example
{
   public static void Main()
   {
      TimeZoneInfo localZone = TimeZoneInfo.Local;
      Console.WriteLine("Local Time Zone ID: {0}", localZone.Id);
      Console.WriteLine("   Display Name is: {0}.", localZone.DisplayName);
      Console.WriteLine("   Standard name is: {0}.", localZone.StandardName);
      Console.WriteLine("   Daylight saving name is: {0}.", localZone.DaylightName); 
   }
}
// The example displays output like the following:
//     Local Time Zone ID: Pacific Standard Time
//        Display Name is: (UTC-08:00) Pacific Time (US & Canada).
//        Standard name is: Pacific Standard Time.
//        Daylight saving name is: Pacific Daylight Time.
open System

let localZone = TimeZoneInfo.Local
printfn $"Local Time Zone ID: {localZone.Id}"
printfn $"   Display Name is: {localZone.DisplayName}."
printfn $"   Standard name is: {localZone.StandardName}."
printfn $"   Daylight saving name is: {localZone.DaylightName}."
// The example displays output like the following:
//     Local Time Zone ID: Pacific Standard Time
//        Display Name is: (UTC-08:00) Pacific Time (US & Canada).
//        Standard name is: Pacific Standard Time.
//        Daylight saving name is: Pacific Daylight Time.
Module Example
   Public Sub Main()
      Dim localZone As TimeZoneInfo = TimeZoneInfo.Local
      Console.WriteLine("Local Time Zone ID: {0}", localZone.Id)
      Console.WriteLine("   Display Name is: {0}.", localZone.DisplayName)
      Console.WriteLine("   Standard name is: {0}.", localZone.StandardName)
      Console.WriteLine("   Daylight saving name is: {0}.", localZone.DaylightName) 
   End Sub
End Module
' The example displays output like the following:
'     Local Time Zone ID: Pacific Standard Time
'        Display Name is: (UTC-08:00) Pacific Time (US & Canada).
'        Standard name is: Pacific Standard Time.
'        Daylight saving name is: Pacific Daylight Time.

Remarks

The local time zone is the time zone on the computer where the code is executing.

Important

You should always access the local time zone through the TimeZoneInfo.Local property rather than assigning the local time zone to a TimeZoneInfo object variable. This prevents the TimeZoneInfo object variable from being invalidated by a call to the ClearCachedData method.

On Windows systems, the TimeZoneInfo object returned by the TimeZoneInfo.Local property reflects the setting of the Automatically adjust clock for Daylight Saving Time checkbox in the Control Panel Date and Time application. If the checkbox is unchecked, the cached copy of the local time zone contains no daylight saving time information. This means that:

This is not true, however, if a reference to the local time zone is retrieved using the FindSystemTimeZoneById method.

The Local property corresponds to the CurrentTimeZone property of the TimeZone class.

Applies to

See also