TimeZoneInfo.AdjustmentRule 类

定义

提供有关时区调整的信息,例如与夏令时的相互转换。

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
属性
实现

示例

以下示例检索在本地系统上定义的所有时区,并显示有关其调整规则的完整信息。

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();
   } 
}
type WeekOfMonth = 
    | First = 1
    | Second = 2
    | Third = 3
    | Fourth = 4
    | Last = 5

let showStartAndEndDates () =
    // Get all time zones from system
    let timeZones = TimeZoneInfo.GetSystemTimeZones()
    let monthNames = CultureInfo.CurrentCulture.DateTimeFormat.MonthNames
    // Get each time zone
    for timeZone in timeZones do
        let adjustments = timeZone.GetAdjustmentRules()
        // Display message for time zones with no adjustments
        if adjustments.Length = 0 then
            printfn $"{timeZone.StandardName} has no adjustment rules"
        else
            // Handle time zones with 1 or 2+ adjustments differently
            let mutable ctr = 0
            let showCount, spacer = 
                if adjustments.Length > 1 then
                    true, "   "
                else 
                    false, ""
            printfn $"{timeZone.StandardName} Adjustment rules"

            // Iterate adjustment rules
            for adjustment in adjustments do
                if showCount then
                    printfn $"   Adjustment rule #{ctr + 1}"
                    ctr <- ctr + 1
                // Display general adjustment information
                printfn $"{spacer}   Start Date: {adjustment.DateStart:D}"
                printfn $"{spacer}   End Date: {adjustment.DateEnd:D}"
                printfn $"{spacer}   Time Change: {adjustment.DaylightDelta.Hours}:{adjustment.DaylightDelta.Minutes:D2} hours"
                // Get transition start information
                let transitionStart = adjustment.DaylightTransitionStart
                printf $"{spacer}   Annual Start: "
                if transitionStart.IsFixedDateRule then
                    printfn $"On {monthNames[transitionStart.Month - 1]} {transitionStart.Day} at {transitionStart.TimeOfDay:t}"
                else
                    printfn $"The {transitionStart.Week |> enum<WeekOfMonth>} {transitionStart.DayOfWeek} of {monthNames[transitionStart.Month - 1]} at {transitionStart.TimeOfDay:t}"
                // Get transition end information
                let transitionEnd = adjustment.DaylightTransitionEnd
                printf $"{spacer}   Annual End: "
                if transitionEnd.IsFixedDateRule then
                    printfn $"On {monthNames[transitionEnd.Month - 1]} {transitionEnd.Day} at {transitionEnd.TimeOfDay:t}"
                else
                    printfn $"The {enum<WeekOfMonth> transitionEnd.Week} {transitionEnd.DayOfWeek} of {monthNames[transitionEnd.Month - 1]} at {transitionEnd.TimeOfDay:t}" 
        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

下面是示例生成的输出的一小部分。 确切的输出将因操作系统和运行示例的日期而异。

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 分别定义与夏令时之间的特定时间变化的有效开始和结束日期,以及其增量 (调整导致时区的标准时间) 更改的确切量。 此外,两个属性返回 TimeZoneInfo.TransitionTime 对象,这些对象定义每次转换到标准时间或从标准时间转换的时间。

注意

类的实例是不可变的 TimeZoneInfo.AdjustmentRule 。 创建对象后,无法修改其值。

若要创建 TimeZoneInfo.AdjustmentRule 对象,请在 static Visual Basic) Shared 方法中调用 (TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule 。 然后,可以为 方法的 TimeZoneInfo.AdjustmentRule 两个重载 TimeZoneInfo.CreateCustomTimeZone 提供对象的数组。 若要检索特定时区的调整规则,请调用其 TimeZoneInfo.GetAdjustmentRules 方法,该方法返回对象的数组 TimeZoneInfo.AdjustmentRule

属性

BaseUtcOffsetDelta

获取调整规则期间时区的基 UTC 偏移量的时差。

DateEnd

获取调整规则失效的日期。

DateStart

获取调整规则生效的日期。

DaylightDelta

获取构成时区的夏令时所需的时间量。 将此时间量从协调世界时 (UTC) 添加到时区偏移量。

DaylightTransitionEnd

获取有关每年何时从夏时制转换回标准时间的信息。

DaylightTransitionStart

获取有关每年何时从标准时间转换为夏时制的信息。

方法

CreateAdjustmentRule(DateTime, DateTime, TimeSpan, TimeZoneInfo+TransitionTime, TimeZoneInfo+TransitionTime)

为特定时区创建新调整规则。

CreateAdjustmentRule(DateTime, DateTime, TimeSpan, TimeZoneInfo+TransitionTime, TimeZoneInfo+TransitionTime, TimeSpan)

为特定时区创建新调整规则。

Equals(Object)

指示当前实例是否等于另一个实例。

Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
Equals(TimeZoneInfo+AdjustmentRule)

确定当前 TimeZoneInfo.AdjustmentRule 对象是否等于第二个 TimeZoneInfo.AdjustmentRule 对象。

GetHashCode()

用作哈希算法的哈希函数和数据结构(如哈希表)。

GetType()

获取当前实例的 Type

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
ToString()

返回表示当前对象的字符串。

(继承自 Object)

显式接口实现

IDeserializationCallback.OnDeserialization(Object)

TimeZoneInfo.AdjustmentRule 对象的反序列化完成时运行。

ISerializable.GetObjectData(SerializationInfo, StreamingContext)

使用序列化 SerializationInfo 对象所需的数据填充此对象。

适用于

另请参阅