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类识别仅本地时区,并可以将协调世界时 (UTC) 和当地时间之间的时间转换。The TimeZone class recognizes only the local time zone, and can convert times between Coordinated Universal Time (UTC) and local time. 一个TimeZoneInfo对象可以表示任何时区,以及方法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

获取表示协调世界时 (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)

将协调世界时 (UTC) 转换为指定时区中的时间。Converts a Coordinated Universal Time (UTC) to the time in a specified time zone.

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

将指定的日期和时间转换为协调世界时 (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)

计算此时区中的时间与协调世界时 (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)

计算此时区中的时间与协调世界时 (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)

确定特定时区中的特定日期和时间是否不明确以及是否可以映射至两个或多个协调世界时 (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)

确定特定时区中的特定日期和时间是否不明确以及是否可以映射至两个或多个协调世界时 (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 的浅表副本。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.

适用于