TimeZoneInfo.Local Property

Gets a TimeZoneInfo object that represents the local time zone.

Namespace:  System
Assemblies:   mscorlib (in mscorlib.dll)
  System.Runtime (in System.Runtime.dll)

public static TimeZoneInfo Local { get; }

Property Value

Type: System.TimeZoneInfo
An object that represents the local time zone.

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

Important noteImportant

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.

The TimeZoneInfo object returned by the TimeZoneInfo.Local property reflects the setting of the Automatically adjust clock for daylight saving changes checkbox or the Automatically adjust clock for Daylight Saving Time checkbox in the Control Panel Date and Time application for Windows XP and Windows Vista, respectively. 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.

Notes to Callers

In converting dates and times, Windows XP recognizes only the current adjustment rule, which it applies to all dates, including down-level dates (that is, dates that are earlier than the starting date of the current adjustment rule). On Windows XP, to prevent local date and time information provided by the Local object from diverging from the date and time information displayed in the system tray, the TimeZoneInfo object returned by the Local property also applies the current adjustment rule to down-level dates. Applications running on Windows XP that require historically accurate local date and time calculations must work around this behavior by using the FindSystemTimeZoneById method to retrieve a TimeZoneInfo object that corresponds to the local time zone.

The following example provides an illustration for a Windows XP system in the U.S. Pacific Time zone. Because the first three method calls all use the local time zone returned by the Local property, they apply the current time zone adjustment rule (which went into effect in 2007) to a date in 2006. The current adjustment rule provides for the transition to daylight saving time to occur on the second Sunday of March; the previous rule, which was in effect in 2006, provided for the transition to daylight saving time to occur on the first Sunday of April. Only the fourth method call, which uses the FindSystemTimeZoneById method to retrieve the local time zone, accurately performs this historical date and time conversion.

using System;

public class Example
{
   public static void Main()
   {
      DateTime date1 = new DateTime(2006, 3, 21, 2, 0, 0);

      Console.WriteLine(date1.ToUniversalTime());
      Console.WriteLine(TimeZoneInfo.ConvertTimeToUtc(date1));
      Console.WriteLine(TimeZoneInfo.ConvertTimeToUtc(date1, TimeZoneInfo.Local));

      TimeZoneInfo tz = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time");  
      Console.WriteLine(TimeZoneInfo.ConvertTimeToUtc(date1, tz));     
   }
}
// The example displays the following output on Windows XP systems: 
//       3/21/2006 9:00:00 AM 
//       3/21/2006 9:00:00 AM 
//       3/21/2006 9:00:00 AM 
//       3/21/2006 10:00:00 AM

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.

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); 

.NET Framework

Supported in: 4.5.3, 4, 3.5

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

Supported in: Windows Phone 8.1

Supported in: Windows Phone Silverlight 8.1

Supported in: Windows Phone Silverlight 8

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft