閱讀英文

共用方式為


TimeZoneInfo.AdjustmentRule 類別

定義

提供有關時區調整的資訊 (例如日光節約時間的來回轉換)。

C#
public sealed class TimeZoneInfo.AdjustmentRule : IEquatable<TimeZoneInfo.AdjustmentRule>, System.Runtime.Serialization.IDeserializationCallback, System.Runtime.Serialization.ISerializable
C#
[System.Serializable]
public sealed class TimeZoneInfo.AdjustmentRule : IEquatable<TimeZoneInfo.AdjustmentRule>, System.Runtime.Serialization.IDeserializationCallback, System.Runtime.Serialization.ISerializable
繼承
TimeZoneInfo.AdjustmentRule
屬性
實作

範例

下列範例會擷取本機系統上定義的所有時區,並顯示其調整規則的完整資訊。

C#
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();
   } 
}

以下是範例所產生的一小部分輸出。 確切的輸出會根據作業系統和執行範例的日期而有所不同。

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 物件,請在 Visual Basic) 方法中呼叫 static (SharedTimeZoneInfo.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 物件中填入將這個物件序列化時所需的資料。

適用於

產品 版本
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
.NET Standard 2.0, 2.1

另請參閱