Export (0) Print
Expand All

TimeZoneInfo Class

Represents any time zone in the world.

System.Object
  System.TimeZoneInfo

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 propertyBaseUtcOffsetGets the time difference between the current time zone's standard time and Coordinated Universal Time (UTC).
Public propertyDaylightNameGets the localized display name for the current time zone's daylight saving time.
Public propertyDisplayNameGets the localized general display name that represents the time zone.
Public propertyIdGets the time zone identifier.
Public propertyStatic memberLocalGets a TimeZoneInfo object that represents the local time zone.
Public propertyStandardNameGets the localized display name for the time zone's standard time.
Public propertySupportsDaylightSavingTimeGets a value indicating whether the time zone has any daylight saving time rules.
Public propertyStatic memberUtcGets a TimeZoneInfo object that represents the Coordinated Universal Time (UTC) zone.
Top

  NameDescription
Public methodStatic memberClearCachedDataClears cached time zone data.
Public methodStatic memberConvertTime(DateTime, TimeZoneInfo)Converts a time to the time in a particular time zone.
Public methodStatic memberConvertTime(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 current 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 methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Public methodEquals(TimeZoneInfo)Determines whether the current TimeZoneInfo object and another TimeZoneInfo object are equal.
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
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 methodGetAmbiguousTimeOffsets(DateTime)Returns information about the possible dates and times that an ambiguous date and time can be mapped to.
Public methodGetAmbiguousTimeOffsets(DateTimeOffset)Returns information about the possible dates and times that an ambiguous date and time can be mapped to.
Public methodGetHashCodeServes 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 methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodGetUtcOffset(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 methodGetUtcOffset(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 methodIsAmbiguousTime(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 methodIsAmbiguousTime(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 methodIsDaylightSavingTime(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 methodIsDaylightSavingTime(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 methodIsInvalidTimeIndicates whether a particular date and time is invalid.
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToSerializedStringConverts the current TimeZoneInfo object to a serialized string.
Public methodToStringReturns 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, 3.5

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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.

Community Additions

ADD
Show:
© 2014 Microsoft