TimeZoneInfo TimeZoneInfo TimeZoneInfo TimeZoneInfo Class

Definition

Represents any time zone in the world.

public ref class TimeZoneInfo sealed : IEquatable<TimeZoneInfo ^>, System::Runtime::Serialization::IDeserializationCallback, System::Runtime::Serialization::ISerializable
[System.Serializable]
public sealed class TimeZoneInfo : IEquatable<TimeZoneInfo>, System.Runtime.Serialization.IDeserializationCallback, System.Runtime.Serialization.ISerializable
type TimeZoneInfo = class
    interface IEquatable<TimeZoneInfo>
    interface IDeserializationCallback
    interface ISerializable
Public NotInheritable Class TimeZoneInfo
Implements IDeserializationCallback, IEquatable(Of TimeZoneInfo), ISerializable
Inheritance
TimeZoneInfoTimeZoneInfoTimeZoneInfoTimeZoneInfo
Attributes
Implements

Remarks

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.

Note

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 based on its 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 on Windows systems or by the time zone classes in the ICU Library on Linux or macOS. 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.

Properties

BaseUtcOffset BaseUtcOffset BaseUtcOffset BaseUtcOffset

Gets the time difference between the current time zone's standard time and Coordinated Universal Time (UTC).

DaylightName DaylightName DaylightName DaylightName

Gets the display name for the current time zone's daylight saving time.

DisplayName DisplayName DisplayName DisplayName

Gets the general display name that represents the time zone.

Id Id Id Id

Gets the time zone identifier.

Local Local Local Local

Gets a TimeZoneInfo object that represents the local time zone.

StandardName StandardName StandardName StandardName

Gets the display name for the time zone's standard time.

SupportsDaylightSavingTime SupportsDaylightSavingTime SupportsDaylightSavingTime SupportsDaylightSavingTime

Gets a value indicating whether the time zone has any daylight saving time rules.

Utc Utc Utc Utc

Gets a TimeZoneInfo object that represents the Coordinated Universal Time (UTC) zone.

Methods

ClearCachedData() ClearCachedData() ClearCachedData() ClearCachedData()

Clears cached time zone data.

ConvertTime(DateTime, TimeZoneInfo) ConvertTime(DateTime, TimeZoneInfo) ConvertTime(DateTime, TimeZoneInfo) ConvertTime(DateTime, TimeZoneInfo)

Converts a time to the time in a particular time zone.

ConvertTime(DateTime, TimeZoneInfo, TimeZoneInfo) ConvertTime(DateTime, TimeZoneInfo, TimeZoneInfo) ConvertTime(DateTime, TimeZoneInfo, TimeZoneInfo) ConvertTime(DateTime, TimeZoneInfo, TimeZoneInfo)

Converts a time from one time zone to another.

ConvertTime(DateTimeOffset, TimeZoneInfo) ConvertTime(DateTimeOffset, TimeZoneInfo) ConvertTime(DateTimeOffset, TimeZoneInfo) ConvertTime(DateTimeOffset, TimeZoneInfo)

Converts a time to the time in a particular time zone.

ConvertTimeBySystemTimeZoneId(DateTime, String) ConvertTimeBySystemTimeZoneId(DateTime, String) ConvertTimeBySystemTimeZoneId(DateTime, String) ConvertTimeBySystemTimeZoneId(DateTime, String)

Converts a time to the time in another time zone based on the time zone's identifier.

ConvertTimeBySystemTimeZoneId(DateTime, String, String) ConvertTimeBySystemTimeZoneId(DateTime, String, String) ConvertTimeBySystemTimeZoneId(DateTime, String, String) ConvertTimeBySystemTimeZoneId(DateTime, String, String)

Converts a time from one time zone to another based on time zone identifiers.

ConvertTimeBySystemTimeZoneId(DateTimeOffset, String) ConvertTimeBySystemTimeZoneId(DateTimeOffset, String) ConvertTimeBySystemTimeZoneId(DateTimeOffset, String) ConvertTimeBySystemTimeZoneId(DateTimeOffset, String)

Converts a time to the time in another time zone based on the time zone's identifier.

ConvertTimeFromUtc(DateTime, TimeZoneInfo) ConvertTimeFromUtc(DateTime, TimeZoneInfo) ConvertTimeFromUtc(DateTime, TimeZoneInfo) ConvertTimeFromUtc(DateTime, TimeZoneInfo)

Converts a Coordinated Universal Time (UTC) to the time in a specified time zone.

ConvertTimeToUtc(DateTime) ConvertTimeToUtc(DateTime) ConvertTimeToUtc(DateTime) ConvertTimeToUtc(DateTime)

Converts the specified date and time to Coordinated Universal Time (UTC).

ConvertTimeToUtc(DateTime, TimeZoneInfo) ConvertTimeToUtc(DateTime, TimeZoneInfo) ConvertTimeToUtc(DateTime, TimeZoneInfo) ConvertTimeToUtc(DateTime, TimeZoneInfo)

Converts the time in a specified time zone to Coordinated Universal Time (UTC).

CreateCustomTimeZone(String, TimeSpan, String, String) CreateCustomTimeZone(String, TimeSpan, String, String) CreateCustomTimeZone(String, TimeSpan, String, String) CreateCustomTimeZone(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.

CreateCustomTimeZone(String, TimeSpan, String, String, String, TimeZoneInfo+AdjustmentRule[]) CreateCustomTimeZone(String, TimeSpan, String, String, String, TimeZoneInfo+AdjustmentRule[]) CreateCustomTimeZone(String, TimeSpan, String, String, String, TimeZoneInfo+AdjustmentRule[]) CreateCustomTimeZone(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.

CreateCustomTimeZone(String, TimeSpan, String, String, String, TimeZoneInfo+AdjustmentRule[], Boolean) CreateCustomTimeZone(String, TimeSpan, String, String, String, TimeZoneInfo+AdjustmentRule[], Boolean) CreateCustomTimeZone(String, TimeSpan, String, String, String, TimeZoneInfo+AdjustmentRule[], Boolean) CreateCustomTimeZone(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.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Determines whether the current TimeZoneInfo object and another object are equal.

Equals(TimeZoneInfo) Equals(TimeZoneInfo) Equals(TimeZoneInfo) Equals(TimeZoneInfo)

Determines whether the current TimeZoneInfo object and another TimeZoneInfo object are equal.

FindSystemTimeZoneById(String) FindSystemTimeZoneById(String) FindSystemTimeZoneById(String) FindSystemTimeZoneById(String)

Instantiates a new TimeZoneInfo object based on its identifier.

FromSerializedString(String) FromSerializedString(String) FromSerializedString(String) FromSerializedString(String)

Deserializes a string to re-create an original serialized TimeZoneInfo object.

GetAdjustmentRules() GetAdjustmentRules() GetAdjustmentRules() GetAdjustmentRules()

Retrieves an array of TimeZoneInfo.AdjustmentRule objects that apply to the current TimeZoneInfo object.

GetAmbiguousTimeOffsets(DateTime) GetAmbiguousTimeOffsets(DateTime) GetAmbiguousTimeOffsets(DateTime) GetAmbiguousTimeOffsets(DateTime)

Returns information about the possible dates and times that an ambiguous date and time can be mapped to.

GetAmbiguousTimeOffsets(DateTimeOffset) GetAmbiguousTimeOffsets(DateTimeOffset) GetAmbiguousTimeOffsets(DateTimeOffset) GetAmbiguousTimeOffsets(DateTimeOffset)

Returns information about the possible dates and times that an ambiguous date and time can be mapped to.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Serves as a hash function for hashing algorithms and data structures such as hash tables.

GetSystemTimeZones() GetSystemTimeZones() GetSystemTimeZones() GetSystemTimeZones()

Returns a sorted collection of all the time zones about which information is available on the local system.

GetType() GetType() GetType() GetType()

Gets the Type of the current instance.

(Inherited from Object)
GetUtcOffset(DateTime) GetUtcOffset(DateTime) GetUtcOffset(DateTime) GetUtcOffset(DateTime)

Calculates the offset or difference between the time in this time zone and Coordinated Universal Time (UTC) for a particular date and time.

GetUtcOffset(DateTimeOffset) GetUtcOffset(DateTimeOffset) GetUtcOffset(DateTimeOffset) GetUtcOffset(DateTimeOffset)

Calculates the offset or difference between the time in this time zone and Coordinated Universal Time (UTC) for a particular date and time.

HasSameRules(TimeZoneInfo) HasSameRules(TimeZoneInfo) HasSameRules(TimeZoneInfo) HasSameRules(TimeZoneInfo)

Indicates whether the current object and another TimeZoneInfo object have the same adjustment rules.

IsAmbiguousTime(DateTime) IsAmbiguousTime(DateTime) IsAmbiguousTime(DateTime) IsAmbiguousTime(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.

IsAmbiguousTime(DateTimeOffset) IsAmbiguousTime(DateTimeOffset) IsAmbiguousTime(DateTimeOffset) IsAmbiguousTime(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.

IsDaylightSavingTime(DateTime) IsDaylightSavingTime(DateTime) IsDaylightSavingTime(DateTime) IsDaylightSavingTime(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.

IsDaylightSavingTime(DateTimeOffset) IsDaylightSavingTime(DateTimeOffset) IsDaylightSavingTime(DateTimeOffset) IsDaylightSavingTime(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.

IsInvalidTime(DateTime) IsInvalidTime(DateTime) IsInvalidTime(DateTime) IsInvalidTime(DateTime)

Indicates whether a particular date and time is invalid.

MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
ToSerializedString() ToSerializedString() ToSerializedString() ToSerializedString()

Converts the current TimeZoneInfo object to a serialized string.

ToString() ToString() ToString() ToString()

Returns the current TimeZoneInfo object's display name.

Explicit Interface Implementations

IDeserializationCallback.OnDeserialization(Object) IDeserializationCallback.OnDeserialization(Object) IDeserializationCallback.OnDeserialization(Object) IDeserializationCallback.OnDeserialization(Object)

Runs when the deserialization of an object has been completed.

ISerializable.GetObjectData(SerializationInfo, StreamingContext) ISerializable.GetObjectData(SerializationInfo, StreamingContext) ISerializable.GetObjectData(SerializationInfo, StreamingContext) ISerializable.GetObjectData(SerializationInfo, StreamingContext)

Populates a SerializationInfo object with the data needed to serialize the current TimeZoneInfo object.

Applies to