TimeZoneInfo TimeZoneInfo TimeZoneInfo TimeZoneInfo Class

定義

表示世界的任意時區。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 ISerializable
    interface IDeserializationCallback
Public NotInheritable Class TimeZoneInfo
Implements IDeserializationCallback, IEquatable(Of TimeZoneInfo), ISerializable
繼承
TimeZoneInfoTimeZoneInfoTimeZoneInfoTimeZoneInfo
屬性
實作

備註

時區是使用相同時間的地理區域。A time zone is a geographical region in which the same time is used.

TimeZoneInfo類別會提供顯著的增強功能比TimeZone類別,可提供有限的功能。The TimeZoneInfo class offers significant enhancements over the TimeZone class, which provides only limited functionality.

TimeZone類別能夠辨識只有當地時區,並將 Coordinated Universal Time (UTC) 與當地時間之間的時間可以轉換。The TimeZone class recognizes only the local time zone, and can convert times between Coordinated Universal Time (UTC) and local time. ATimeZoneInfo物件可以代表任何時區和方法TimeZoneInfo類別可用來將一個時區中的時間轉換成任何其他時區中對應的時間。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. 成員TimeZoneInfo類別支援下列作業: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.

注意

執行個體TimeZoneInfo類別是不變。An instance of the TimeZoneInfo class is immutable. 一旦具現化物件,則無法修改其值。Once an object has been instantiated, its values cannot be modified.

您無法執行個體化TimeZoneInfo物件使用new關鍵字。You cannot instantiate a TimeZoneInfo object using the new keyword. 相反地,您必須呼叫其中一個靜態成員的TimeZoneInfo下表所示的類別。Instead, you must call one of the static members of the TimeZoneInfo class shown in the following table.

靜態成員名稱Static member name 描述Description
CreateCustomTimeZone 方法CreateCustomTimeZone method 從應用程式所提供的資料建立自訂時區。Creates a custom time zone from application-supplied data.
FindSystemTimeZoneById 方法FindSystemTimeZoneById method 具現化時區,根據其識別項。Instantiates a time zone based on its identifier.
FromSerializedString 方法FromSerializedString method 還原序列化的字串值來重新建立先前序列化TimeZoneInfo物件。Deserializes a string value to re-create a previously serialized TimeZoneInfo object.
GetSystemTimeZones 方法GetSystemTimeZones method 傳回可列舉ReadOnlyCollection<T>TimeZoneInfo物件,表示所有本機系統可用的時區。Returns an enumerable ReadOnlyCollection<T> of TimeZoneInfo objects that represents all time zones that are available on the local system.
Local 屬性Local property 具現化TimeZoneInfo代表當地時區的物件。Instantiates a TimeZoneInfo object that represents the local time zone.
Utc 屬性Utc property 具現化TimeZoneInfo代表 UTC 時區的物件。Instantiates a TimeZoneInfo object that represents the UTC zone.

您可以使用CreateCustomTimeZone方法用來建立本機系統登錄在 Windows 系統或時區中的類別中未定義的時區ICU 文件庫Linux 或 macOS 上。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. 您可以接著使用ToSerializedString儲存為字串時,這些都可以儲存至應用程式存取某種形式的時區物件之資訊的屬性。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. 您可以使用FromSerializedString方法,將序列化的字串轉換回TimeZoneInfo物件。You can use the FromSerializedString method to convert a serialized string back to a TimeZoneInfo object.

屬性

BaseUtcOffset BaseUtcOffset BaseUtcOffset BaseUtcOffset

取得目前時區標準時間與國際標準時間 (UTC) 的時差。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

取得表示本地時區的 TimeZoneInfo 物件。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

取得表示 Coordinated Universal Time (UTC) 時區的 TimeZoneInfo 物件。Gets a TimeZoneInfo object that represents the Coordinated Universal Time (UTC) zone.

方法

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)

將 Coordinated Universal Time (UTC) 轉換為指定時區的時間。Converts a Coordinated Universal Time (UTC) to the time in a specified time zone.

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

將指定的日期和時間轉換為 Coordinated Universal Time (UTC)。Converts the specified date and time to Coordinated Universal Time (UTC).

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

將指定時區的時間轉換為國際標準時間 (UTC)。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)

建立具有指定識別項的自訂時區、國際標準時間 (UTC) 的位移、顯示名稱和標準時間顯示名稱。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[])

以指定的識別項、國際標準時間 (UTC) 的位移、顯示名稱、標準時間名稱、日光節約時間名稱和日光節約時間規則,建立自訂時區。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)

以指定的識別項、國際標準時間 (UTC) 的位移、顯示名稱、標準時間名稱、日光節約時間名稱、日光節約時間規則,以及表示傳回的物件是否反映日光節約時間資訊的值,建立自訂時區。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)

判斷目前的 TimeZoneInfo 物件與另一個物件是否相等。Determines whether the current TimeZoneInfo object and another object are equal.

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

判斷目前的 TimeZoneInfo 物件和另一個 TimeZoneInfo 物件是否相等。Determines whether the current TimeZoneInfo object and another TimeZoneInfo object are equal.

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

根據新 TimeZoneInfo 物件的識別碼加以具現化。Instantiates a new TimeZoneInfo object based on its identifier.

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

還原序列化字串,以重新建立原始的序列化 TimeZoneInfo 物件。Deserializes a string to re-create an original serialized TimeZoneInfo object.

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

擷取會套用至目前 TimeZoneInfo.AdjustmentRule 物件的 TimeZoneInfo 物件陣列。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()

取得目前執行個體的 TypeGets the Type of the current instance.

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

計算這個時區與 Coordinated Universal Time (UTC) 在特定日期和時間的位移和差異。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)

計算這個時區與 Coordinated Universal Time (UTC) 在特定日期和時間的位移和差異。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)

指出目前物件與另一個 TimeZoneInfo 物件是否具有相同的調整規則。Indicates whether the current object and another TimeZoneInfo object have the same adjustment rules.

IsAmbiguousTime(DateTime) IsAmbiguousTime(DateTime) IsAmbiguousTime(DateTime) IsAmbiguousTime(DateTime)

判斷特定時區中的特定日期和時間是否模稜兩可,以及是否可對應到兩個或多個 Coordinated Universal Time (UTC) 時間。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)

判斷特定時區中的特定日期和時間是否模稜兩可,以及是否可對應到兩個或多個 Coordinated Universal Time (UTC) 時間。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)

表示指定的日期和時間是否在目前 TimeZoneInfo 物件時區的日光節約時間範圍內。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)

表示指定的日期和時間是否在目前 TimeZoneInfo 物件時區的日光節約時間範圍內。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()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

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

將目前的 TimeZoneInfo 物件轉換為序列化字串。Converts the current TimeZoneInfo object to a serialized string.

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

傳回目前 TimeZoneInfo 物件的顯示名稱。Returns the current TimeZoneInfo object's display name.

明確介面實作

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)

使用序列化目前 SerializationInfo 物件所需的資料,填入 TimeZoneInfo 物件。Populates a SerializationInfo object with the data needed to serialize the current TimeZoneInfo object.

適用於