TimeZoneInfo 類別

定義

表示世界的任意時區。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
繼承
TimeZoneInfo
屬性
實作

備註

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

類別在TimeZone類別上提供了顯著的增強功能, 只提供有限的功能。 TimeZoneInfoThe TimeZoneInfo class offers significant enhancements over the TimeZone class, which provides only limited functionality.

TimeZone類別只會辨識當地時區, 而且可以在國際標準時間 (UTC) 和當地時間之間轉換時間。The TimeZone class recognizes only the local time zone, and can convert times between Coordinated Universal Time (UTC) and local time. 物件可以代表任何時區, 而TimeZoneInfo類別的方法可以用來將某個時區的時間轉換為任何其他時區的對應時間。 TimeZoneInfoA 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 傳回TimeZoneInfo物件的ReadOnlyCollection<T>可列舉, 表示本機系統上可用的所有時區。Returns an enumerable ReadOnlyCollection<T> of TimeZoneInfo objects that represents all time zones that are available on the local system.
Local 屬性Local property 具現化代表當地時區的物件。TimeZoneInfoInstantiates a TimeZoneInfo object that represents the local time zone.
Utc 屬性Utc property 具現化代表 UTC 區域的物件。TimeZoneInfoInstantiates a TimeZoneInfo object that represents the UTC zone.

您可以使用CreateCustomTimeZone方法, 在 Windows 系統上的本機系統登錄或 Linux 或 macOS 上的ICU 程式庫中的時區類別, 建立未定義的時區。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

取得目前時區標準時間與國際標準時間 (UTC) 的時差。Gets the time difference between the current time zone's standard time and Coordinated Universal Time (UTC).

DaylightName

取得目前時區日光節約時間的顯示名稱。Gets the display name for the current time zone's daylight saving time.

DisplayName

取得表示時區的一般顯示名稱。Gets the general display name that represents the time zone.

Id

取得時區識別項。Gets the time zone identifier.

Local

取得表示本地時區的 TimeZoneInfo 物件。Gets a TimeZoneInfo object that represents the local time zone.

StandardName

取得時區標準時間的顯示名稱。Gets the display name for the time zone's standard time.

SupportsDaylightSavingTime

取得值,這個值表示時區是否具有任何日光節約時間規則。Gets a value indicating whether the time zone has any daylight saving time rules.

Utc

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

方法

ClearCachedData()

清除快取的時區資料。Clears cached time zone data.

ConvertTime(DateTime, TimeZoneInfo)

將時間轉換為特定時區的時間。Converts a time to the time in a particular time zone.

ConvertTime(DateTime, TimeZoneInfo, TimeZoneInfo)

將時間從一個時區轉換為另一個時區。Converts a time from one time zone to another.

ConvertTime(DateTimeOffset, TimeZoneInfo)

將時間轉換為特定時區的時間。Converts a time to the time in a particular time zone.

ConvertTimeBySystemTimeZoneId(DateTime, String)

根據時區的識別項將時間轉換為另一時區的時間。Converts a time to the time in another time zone based on the time zone's identifier.

ConvertTimeBySystemTimeZoneId(DateTime, String, String)

根據時區識別項將時間從一個時區轉換為另一個時區。Converts a time from one time zone to another based on time zone identifiers.

ConvertTimeBySystemTimeZoneId(DateTimeOffset, String)

根據時區的識別項將時間轉換為另一時區的時間。Converts a time to the time in another time zone based on the time zone's identifier.

ConvertTimeFromUtc(DateTime, TimeZoneInfo)

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

ConvertTimeToUtc(DateTime)

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

ConvertTimeToUtc(DateTime, TimeZoneInfo)

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

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[])

以指定的識別項、國際標準時間 (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)

以指定的識別項、國際標準時間 (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)

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

Equals(TimeZoneInfo)

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

FindSystemTimeZoneById(String)

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

FromSerializedString(String)

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

GetAdjustmentRules()

擷取會套用至目前 TimeZoneInfo.AdjustmentRule 物件的 TimeZoneInfo 物件陣列。Retrieves an array of TimeZoneInfo.AdjustmentRule objects that apply to the current TimeZoneInfo object.

GetAmbiguousTimeOffsets(DateTime)

傳回不明確的日期和時間可能對應的日期和時間相關資訊。Returns information about the possible dates and times that an ambiguous date and time can be mapped to.

GetAmbiguousTimeOffsets(DateTimeOffset)

傳回不明確的日期和時間可能對應的日期和時間相關資訊。Returns information about the possible dates and times that an ambiguous date and time can be mapped to.

GetHashCode()

做為雜湊函式,用於雜湊演算法和資料結構,例如雜湊資料表。Serves as a hash function for hashing algorithms and data structures such as hash tables.

GetSystemTimeZones()

傳回本機系統上有其資訊之所有時區的排序集合。Returns a sorted collection of all the time zones about which information is available on the local system.

GetType()

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

(繼承來源 Object)
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)

計算這個時區與 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)

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

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)

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

表示指定的日期和時間是否在目前 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)

表示指定的日期和時間是否在目前 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)

指出特定日期和時間是否無效。Indicates whether a particular date and time is invalid.

MemberwiseClone()

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

(繼承來源 Object)
ToSerializedString()

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

ToString()

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

明確介面實作

IDeserializationCallback.OnDeserialization(Object)

在物件完成還原序列化時執行。Runs when the deserialization of an object has been completed.

ISerializable.GetObjectData(SerializationInfo, StreamingContext)

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

適用於