TimeZoneInfo.AdjustmentRule 类
定义
提供有关时区调整的信息,例如与夏令时的相互转换。Provides information about a time zone adjustment, such as the transition to and from daylight saving time.
public: ref class TimeZoneInfo::AdjustmentRule sealed : IEquatable<TimeZoneInfo::AdjustmentRule ^>, System::Runtime::Serialization::IDeserializationCallback, System::Runtime::Serialization::ISerializable
public sealed class TimeZoneInfo.AdjustmentRule : IEquatable<TimeZoneInfo.AdjustmentRule>, System.Runtime.Serialization.IDeserializationCallback, System.Runtime.Serialization.ISerializable
[System.Serializable]
public sealed class TimeZoneInfo.AdjustmentRule : IEquatable<TimeZoneInfo.AdjustmentRule>, System.Runtime.Serialization.IDeserializationCallback, System.Runtime.Serialization.ISerializable
type TimeZoneInfo.AdjustmentRule = class
interface IEquatable<TimeZoneInfo.AdjustmentRule>
interface IDeserializationCallback
interface ISerializable
type TimeZoneInfo.AdjustmentRule = class
interface IDeserializationCallback
interface ISerializable
interface IEquatable<TimeZoneInfo.AdjustmentRule>
[<System.Serializable>]
type TimeZoneInfo.AdjustmentRule = class
interface IEquatable<TimeZoneInfo.AdjustmentRule>
interface ISerializable
interface IDeserializationCallback
Public NotInheritable Class TimeZoneInfo.AdjustmentRule
Implements IDeserializationCallback, IEquatable(Of TimeZoneInfo.AdjustmentRule), ISerializable
- 继承
-
TimeZoneInfo.AdjustmentRule
- 属性
- 实现
示例
下面的示例检索在本地系统上定义的所有时区,并显示有关其调整规则的完整信息。The following example retrieves all time zones defined on the local system and displays complete information about their adjustment rules.
private enum WeekOfMonth
{
First = 1,
Second = 2,
Third = 3,
Fourth = 4,
Last = 5,
}
private static void ShowStartAndEndDates()
{
// Get all time zones from system
ReadOnlyCollection<TimeZoneInfo> timeZones = TimeZoneInfo.GetSystemTimeZones();
string[] monthNames = CultureInfo.CurrentCulture.DateTimeFormat.MonthNames;
// Get each time zone
foreach (TimeZoneInfo timeZone in timeZones)
{
TimeZoneInfo.AdjustmentRule[] adjustments = timeZone.GetAdjustmentRules();
// Display message for time zones with no adjustments
if (adjustments.Length == 0)
{
Console.WriteLine("{0} has no adjustment rules", timeZone.StandardName);
}
else
{
// Handle time zones with 1 or 2+ adjustments differently
bool showCount = false;
int ctr = 0;
string spacer = "";
Console.WriteLine("{0} Adjustment rules", timeZone.StandardName);
if (adjustments.Length > 1)
{
showCount = true;
spacer = " ";
}
// Iterate adjustment rules
foreach (TimeZoneInfo.AdjustmentRule adjustment in adjustments)
{
if (showCount)
{
Console.WriteLine(" Adjustment rule #{0}", ctr+1);
ctr++;
}
// Display general adjustment information
Console.WriteLine("{0} Start Date: {1:D}", spacer, adjustment.DateStart);
Console.WriteLine("{0} End Date: {1:D}", spacer, adjustment.DateEnd);
Console.WriteLine("{0} Time Change: {1}:{2:00} hours", spacer,
adjustment.DaylightDelta.Hours, adjustment.DaylightDelta.Minutes);
// Get transition start information
TimeZoneInfo.TransitionTime transitionStart = adjustment.DaylightTransitionStart;
Console.Write("{0} Annual Start: ", spacer);
if (transitionStart.IsFixedDateRule)
{
Console.WriteLine("On {0} {1} at {2:t}",
monthNames[transitionStart.Month - 1],
transitionStart.Day,
transitionStart.TimeOfDay);
}
else
{
Console.WriteLine("The {0} {1} of {2} at {3:t}",
((WeekOfMonth)transitionStart.Week).ToString(),
transitionStart.DayOfWeek.ToString(),
monthNames[transitionStart.Month - 1],
transitionStart.TimeOfDay);
}
// Get transition end information
TimeZoneInfo.TransitionTime transitionEnd = adjustment.DaylightTransitionEnd;
Console.Write("{0} Annual End: ", spacer);
if (transitionEnd.IsFixedDateRule)
{
Console.WriteLine("On {0} {1} at {2:t}",
monthNames[transitionEnd.Month - 1],
transitionEnd.Day,
transitionEnd.TimeOfDay);
}
else
{
Console.WriteLine("The {0} {1} of {2} at {3:t}",
((WeekOfMonth)transitionEnd.Week).ToString(),
transitionEnd.DayOfWeek.ToString(),
monthNames[transitionEnd.Month - 1],
transitionEnd.TimeOfDay);
}
}
}
Console.WriteLine();
}
}
Private Enum WeekOfMonth As Integer
First = 1
Second = 2
Third = 3
Fourth = 4
Last = 5
End Enum
Private Sub ShowStartAndEndDates()
' Get all time zones from system
Dim timeZones As ReadOnlyCollection(Of TimeZoneInfo) = TimeZoneInfo.GetSystemTimeZones()
' Get each time zone
For Each timeZone As TimeZoneInfo In timeZones
Dim adjustments() As TimeZoneInfo.AdjustmentRule = timeZone.GetAdjustmentRules()
' Display message for time zones with no adjustments
If adjustments.Length = 0 Then
Console.WriteLine("{0} has no adjustment rules", timeZone.StandardName)
Else
' Handle time zones with 1 or 2+ adjustments differently
Dim showCount As Boolean = False
Dim ctr As Integer = 0
Dim spacer As String = ""
Console.WriteLine("{0} Adjustment rules", timeZone.StandardName)
If adjustments.Length > 1 Then showCount = True : spacer = " "
' Iterate adjustment rules
For Each adjustment As TimeZoneInfo.AdjustmentRule in adjustments
If showCount Then
Console.WriteLine(" Adjustment rule #{0}", ctr+1)
ctr += 1
End If
' Display general adjustment information
Console.WriteLine("{0} Start Date: {1:D}", spacer, adjustment.DateStart)
Console.WriteLine("{0} End Date: {1:D}", spacer, adjustment.DateEnd)
Console.WriteLine("{0} Time Change: {1}:{2:00} hours", spacer, _
adjustment.DaylightDelta.Hours, adjustment.DaylightDelta.Minutes)
' Get transition start information
Dim transitionStart As TimeZoneInfo.TransitionTime = adjustment.DaylightTransitionStart
Console.Write("{0} Annual Start: ", spacer)
If transitionStart.IsFixedDateRule Then
Console.WriteLine("On {0} {1} at {2:t}", _
MonthName(transitionStart.Month), _
transitionStart.Day, _
transitionStart.TimeOfDay)
Else
Console.WriteLine("The {0} {1} of {2} at {3:t}", _
CType(transitionStart.Week, WeekOfMonth).ToString(), _
transitionStart.DayOfWeek.ToString(), _
MonthName(transitionStart.Month), _
transitionStart.TimeOfDay)
End If
' Get transition end information
Dim transitionEnd As TimeZoneInfo.TransitionTime = adjustment.DaylightTransitionEnd
Console.Write("{0} Annual End: ", spacer)
If transitionEnd.IsFixedDateRule Then
Console.WriteLine("On {0} {1} at {2:t}", _
MonthName(transitionEnd.Month), _
transitionEnd.Day, _
transitionEnd.TimeOfDay)
Else
Console.WriteLine("The {0} {1} of {2} at {3:t}", _
CType(transitionEnd.Week, WeekOfMonth).ToString(), _
transitionEnd.DayOfWeek.ToString(), _
MonthName(transitionEnd.Month), _
transitionEnd.TimeOfDay)
End If
Next
End If
Console.WriteLine()
Next
End Sub
下面是此示例生成的一小部分输出。The following is a small portion of the output that is generated by the example. 确切的输出将取决于操作系统和运行此示例的日期。The exact output will vary depending on the operating system and the date on which the example is run.
Morocco Standard Time Adjustment rules
Adjustment rule #1
Start Date: Tuesday, January 01, 2008
End Date: Wednesday, December 31, 2008
Time Change: 1:00 hours
Annual Start: The Last Saturday of May at 11:59 PM
Annual End: The Last Sunday of August at 11:59 PM
Adjustment rule #2
Start Date: Thursday, January 01, 2009
End Date: Thursday, December 31, 2009
Time Change: 1:00 hours
Annual Start: The Last Sunday of May at 11:59 PM
Annual End: The Third Thursday of August at 11:59 PM
Coordinated Universal Time has no adjustment rules
GMT Standard Time Adjustment rules
Start Date: Monday, January 01, 0001
End Date: Friday, December 31, 9999
Time Change: 1:00 hours
Annual Start: The Last Sunday of March at 1:00 AM
Annual End: The Last Sunday of October at 2:00 AM
Greenwich Standard Time has no adjustment rules
W. Europe Standard Time Adjustment rules
Start Date: Monday, January 01, 0001
End Date: Friday, December 31, 9999
Time Change: 1:00 hours
Annual Start: The Last Sunday of March at 2:00 AM
Annual End: The Last Sunday of October at 3:00 AM
Central Europe Standard Time Adjustment rules
Start Date: Monday, January 01, 0001
End Date: Friday, December 31, 9999
Time Change: 1:00 hours
Annual Start: The Last Sunday of March at 2:00 AM
Annual End: The Last Sunday of October at 3:00 AM
Romance Standard Time Adjustment rules
Start Date: Monday, January 01, 0001
End Date: Friday, December 31, 9999
Time Change: 1:00 hours
Annual Start: The Last Sunday of March at 2:00 AM
Annual End: The Last Sunday of October at 3:00 AM
Central European Standard Time Adjustment rules
Start Date: Monday, January 01, 0001
End Date: Friday, December 31, 9999
Time Change: 1:00 hours
Annual Start: The Last Sunday of March at 2:00 AM
Annual End: The Last Sunday of October at 3:00 AM
W. Central Africa Standard Time has no adjustment rules
注解
TimeZoneInfo.AdjustmentRule类定义特定时间更改为夏令时的有效开始日期和结束日期,并分别定义其增量 (调整导致时区标准时间更改) 的精确开始日期和结束日期。The TimeZoneInfo.AdjustmentRule class defines the effective start and end dates of a particular time change to and from daylight saving time, respectively, as well as its delta (the exact amount by which the adjustment causes the time zone's standard time to change). 此外,两个属性返回 TimeZoneInfo.TransitionTime 对象,这些对象用于定义每次发生标准时间转换的时间。In addition, two properties return TimeZoneInfo.TransitionTime objects that define when each transition to and from standard time occurs.
备注
类的实例 TimeZoneInfo.AdjustmentRule 是不可变的。An instance of the TimeZoneInfo.AdjustmentRule class is immutable. 创建对象后,不能修改其值。Once an object has been created, its values cannot be modified.
若要创建 TimeZoneInfo.AdjustmentRule 对象,请调用 static
Shared
Visual Basic) 方法中的 (TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule 。To create a TimeZoneInfo.AdjustmentRule object, call the static
(Shared
in Visual Basic) TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule method. 然后,可以将对象的数组提供 TimeZoneInfo.AdjustmentRule 给该方法的两个重载 TimeZoneInfo.CreateCustomTimeZone 。You can then supply an array of TimeZoneInfo.AdjustmentRule objects to two of the overloads of the TimeZoneInfo.CreateCustomTimeZone method. 若要检索特定时区的调整规则,请调用其 TimeZoneInfo.GetAdjustmentRules 方法,这将返回对象的数组 TimeZoneInfo.AdjustmentRule 。To retrieve the adjustment rules of a particular time zone, call its TimeZoneInfo.GetAdjustmentRules method, which returns an array of TimeZoneInfo.AdjustmentRule objects.
属性
DateEnd |
获取调整规则失效的日期。Gets the date when the adjustment rule ceases to be in effect. |
DateStart |
获取调整规则生效的日期。Gets the date when the adjustment rule takes effect. |
DaylightDelta |
获取构成时区的夏令时所需的时间量。Gets the amount of time that is required to form the time zone's daylight saving time. 将此时间量从协调世界时 (UTC) 添加到时区偏移量。This amount of time is added to the time zone's offset from Coordinated Universal Time (UTC). |
DaylightTransitionEnd |
获取有关每年何时从夏时制转换回标准时间的信息。Gets information about the annual transition from daylight saving time back to standard time. |
DaylightTransitionStart |
获取有关每年何时从标准时间转换为夏时制的信息。Gets information about the annual transition from standard time to daylight saving time. |
方法
CreateAdjustmentRule(DateTime, DateTime, TimeSpan, TimeZoneInfo+TransitionTime, TimeZoneInfo+TransitionTime) |
为特定时区创建新调整规则。Creates a new adjustment rule for a particular time zone. |
Equals(Object) |
确定指定对象是否等于当前对象。Determines whether the specified object is equal to the current object. (继承自 Object) |
Equals(TimeZoneInfo+AdjustmentRule) |
确定当前 TimeZoneInfo.AdjustmentRule 对象是否等于第二个 TimeZoneInfo.AdjustmentRule 对象。Determines whether the current TimeZoneInfo.AdjustmentRule object is equal to a second TimeZoneInfo.AdjustmentRule object. |
GetHashCode() |
用作哈希算法的哈希函数和数据结构(如哈希表)。Serves as a hash function for hashing algorithms and data structures such as hash tables. |
GetType() |
获取当前实例的 Type。Gets the Type of the current instance. (继承自 Object) |
MemberwiseClone() |
创建当前 Object 的浅表副本。Creates a shallow copy of the current Object. (继承自 Object) |
ToString() |
返回表示当前对象的字符串。Returns a string that represents the current object. (继承自 Object) |
显式接口实现
IDeserializationCallback.OnDeserialization(Object) |
在 TimeZoneInfo.AdjustmentRule 对象的反序列化完成时运行。Runs when the deserialization of a TimeZoneInfo.AdjustmentRule object is completed. |
ISerializable.GetObjectData(SerializationInfo, StreamingContext) |
使用序列化 SerializationInfo 对象所需的数据填充此对象。Populates a SerializationInfo object with the data that is required to serialize this object. |