Export (0) Print
Expand All

TimeZoneInfo Class

Represents any time zone in the world.

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

[SerializableAttribute]
[HostProtectionAttribute(SecurityAction.LinkDemand, MayLeakOnAbort = true)]
public sealed class TimeZoneInfo : IEquatable<TimeZoneInfo>, 
	ISerializable, IDeserializationCallback

The TimeZoneInfo type exposes the following members.

  NameDescription
Public propertySupported by Portable Class LibrarySupported in .NET for Windows Store appsBaseUtcOffsetGets the time difference between the current time zone's standard time and Coordinated Universal Time (UTC).
Public propertySupported by Portable Class LibrarySupported in .NET for Windows Store appsDaylightNameGets the display name for the current time zone's daylight saving time.
Public propertySupported by Portable Class LibrarySupported in .NET for Windows Store appsDisplayNameGets the general display name that represents the time zone.
Public propertyIdGets the time zone identifier.
Public propertyStatic memberSupported by Portable Class LibrarySupported in .NET for Windows Store appsLocalGets a TimeZoneInfo object that represents the local time zone.
Public propertySupported by Portable Class LibrarySupported in .NET for Windows Store appsStandardNameGets the display name for the time zone's standard time.
Public propertySupported by Portable Class LibrarySupported in .NET for Windows Store appsSupportsDaylightSavingTimeGets a value indicating whether the time zone has any daylight saving time rules.
Public propertyStatic memberSupported by Portable Class LibrarySupported in .NET for Windows Store appsUtcGets a TimeZoneInfo object that represents the Coordinated Universal Time (UTC) zone.
Top

  NameDescription
Public methodStatic memberClearCachedDataClears cached time zone data.
Public methodStatic memberSupported by Portable Class LibrarySupported in .NET for Windows Store appsConvertTime(DateTime, TimeZoneInfo)Converts a time to the time in a particular time zone.
Public methodStatic memberSupported by Portable Class LibrarySupported in .NET for Windows Store appsConvertTime(DateTimeOffset, TimeZoneInfo)Converts a time to the time in a particular time zone.
Public methodStatic memberConvertTime(DateTime, TimeZoneInfo, TimeZoneInfo)Converts a time from one time zone to another.
Public methodStatic memberConvertTimeBySystemTimeZoneId(DateTime, String)Converts a time to the time in another time zone based on the time zone's identifier.
Public methodStatic memberConvertTimeBySystemTimeZoneId(DateTimeOffset, String)Converts a time to the time in another time zone based on the time zone's identifier.
Public methodStatic memberConvertTimeBySystemTimeZoneId(DateTime, String, String)Converts a time from one time zone to another based on time zone identifiers.
Public methodStatic memberConvertTimeFromUtcConverts a Coordinated Universal Time (UTC) to the time in a specified time zone.
Public methodStatic memberConvertTimeToUtc(DateTime)Converts the specified date and time to Coordinated Universal Time (UTC).
Public methodStatic memberConvertTimeToUtc(DateTime, TimeZoneInfo)Converts the time in a specified time zone to Coordinated Universal Time (UTC).
Public methodStatic memberCreateCustomTimeZone(String, TimeSpan, String, String)Creates a custom time zone with a specified identifier, an offset from Coordinated Universal Time (UTC), a display name, and a standard time display name.
Public methodStatic memberCreateCustomTimeZone(String, TimeSpan, String, String, String, TimeZoneInfo.AdjustmentRule[])Creates a custom time zone with a specified identifier, an offset from Coordinated Universal Time (UTC), a display name, a standard time name, a daylight saving time name, and daylight saving time rules.
Public methodStatic memberCreateCustomTimeZone(String, TimeSpan, String, String, String, TimeZoneInfo.AdjustmentRule[], Boolean)Creates a custom time zone with a specified identifier, an offset from Coordinated Universal Time (UTC), a display name, a standard time name, a daylight saving time name, daylight saving time rules, and a value that indicates whether the returned object reflects daylight saving time information.
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsEquals(Object)Determines whether the current TimeZoneInfo object and another object are equal. (Overrides Object.Equals(Object).)

In .NET Framework Client Profile 4, this member is inherited from Object.Equals(Object).


In Portable Class Library Portable Class Library, this member is inherited from Object.Equals(Object).


In .NET for Windows Store apps Windows 8, this member is inherited from Object.Equals(Object).


In .NET for Windows Phone apps Windows Phone 8.1, this member is inherited from Object.Equals(Object).
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsEquals(TimeZoneInfo)Determines whether the current TimeZoneInfo object and another TimeZoneInfo object are equal.
Public methodStatic memberFindSystemTimeZoneByIdRetrieves a TimeZoneInfo object from the registry based on its identifier.
Public methodStatic memberFromSerializedStringDeserializes a string to re-create an original serialized TimeZoneInfo object.
Public methodGetAdjustmentRulesRetrieves an array of TimeZoneInfo.AdjustmentRule objects that apply to the current TimeZoneInfo object.
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsGetAmbiguousTimeOffsets(DateTime)Returns information about the possible dates and times that an ambiguous date and time can be mapped to.
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsGetAmbiguousTimeOffsets(DateTimeOffset)Returns information about the possible dates and times that an ambiguous date and time can be mapped to.
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsGetHashCodeServes as a hash function for hashing algorithms and data structures such as hash tables. (Overrides Object.GetHashCode().)
Public methodStatic memberGetSystemTimeZonesReturns a sorted collection of all the time zones about which information is available on the local system.
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsGetUtcOffset(DateTime)Calculates the offset or difference between the time in this time zone and Coordinated Universal Time (UTC) for a particular date and time.
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsGetUtcOffset(DateTimeOffset)Calculates the offset or difference between the time in this time zone and Coordinated Universal Time (UTC) for a particular date and time.
Public methodHasSameRulesIndicates whether the current object and another TimeZoneInfo object have the same adjustment rules.
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsIsAmbiguousTime(DateTime)Determines whether a particular date and time in a particular time zone is ambiguous and can be mapped to two or more Coordinated Universal Time (UTC) times.
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsIsAmbiguousTime(DateTimeOffset)Determines whether a particular date and time in a particular time zone is ambiguous and can be mapped to two or more Coordinated Universal Time (UTC) times.
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsIsDaylightSavingTime(DateTime)Indicates whether a specified date and time falls in the range of daylight saving time for the time zone of the current TimeZoneInfo object.
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsIsDaylightSavingTime(DateTimeOffset)Indicates whether a specified date and time falls in the range of daylight saving time for the time zone of the current TimeZoneInfo object.
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsIsInvalidTimeIndicates whether a particular date and time is invalid.
Public methodToSerializedStringConverts the current TimeZoneInfo object to a serialized string.
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsToStringReturns the current TimeZoneInfo object's display name. (Overrides Object.ToString().)
Top

  NameDescription
Explicit interface implemetationPrivate methodIDeserializationCallback.OnDeserializationInfrastructure. Runs when the deserialization of an object has been completed.
Explicit interface implemetationPrivate methodISerializable.GetObjectDataInfrastructure. Populates a SerializationInfo object with the data needed to serialize the current TimeZoneInfo object.
Top

A time zone is a geographical region in which the same time is used.

The TimeZoneInfo class offers significant enhancements over the TimeZone class, which provides only limited functionality.

The TimeZone class recognizes only the local time zone, and can convert times between Coordinated Universal Time (UTC) and local time. A TimeZoneInfo object can represent any time zone, and methods of the TimeZoneInfo class can be used to convert the time in one time zone to the corresponding time in any other time zone. The members of the TimeZoneInfo class support the following operations:

  • Retrieving a time zone that is already defined by the operating system.

  • Enumerating the time zones that are available on a system.

  • Converting times between different time zones.

  • Creating a new time zone that is not already defined by the operating system.

  • Serializing a time zone for later retrieval.

NoteNote

An instance of the TimeZoneInfo class is immutable. Once an object has been instantiated, its values cannot be modified.

You cannot instantiate a TimeZoneInfo object using the new keyword. Instead, you must call one of the static members of the TimeZoneInfo class shown in the following table.

Static member name

Description

CreateCustomTimeZone method

Creates a custom time zone from application-supplied data.

FindSystemTimeZoneById method

Instantiates a time zone defined in the system registry based on the zone's identifier.

FromSerializedString method

Deserializes a string value to re-create a previously serialized TimeZoneInfo object.

GetSystemTimeZones method

Returns an enumerable ReadOnlyCollection<T> of TimeZoneInfo objects that represents all time zones that are available on the local system.

Local property

Instantiates a TimeZoneInfo object that represents the local time zone.

Utc property

Instantiates a TimeZoneInfo object that represents the UTC zone.

You can use the CreateCustomTimeZone method to create a time zone that is not defined in the local system registry. You can then use the ToSerializedString property to save the time zone object's information as a string, which can be stored in some form that is accessible to the application. You can use the FromSerializedString method to convert a serialized string back to a TimeZoneInfo object.

NoteNote

The HostProtectionAttribute attribute applied to this type or member has the following Resources property value: MayLeakOnAbort. The HostProtectionAttribute does not affect desktop applications (which are typically started by double-clicking an icon, typing a command, or entering a URL in a browser). For more information, see the HostProtectionAttribute class or SQL Server Programming and Host Protection Attributes.

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 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

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone 8, Silverlight 8.1

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.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2014 Microsoft