TimeZoneInfo.TransitionTime.Week 屬性

定義

取得發生時間變更的當月週次。Gets the week of the month in which a time change occurs.

public:
 property int Week { int get(); };
public int Week { get; }
member this.Week : int
Public ReadOnly Property Week As Integer

屬性值

發生時間變更的當月週次。The week of the month in which the time change occurs.

範例

下列範例會列舉在本機電腦上找到的時區,並顯示所有浮動日期轉換的轉換時間資訊。The following example enumerates the time zones found on the local computer and displays transition time information for all floating-date transitions. 時間資訊包含發生時間變更的月份周。The time information includes the week of the month in which the time change occurs. 此範例也會定義WeekOfMonth列舉,以顯示代表Week屬性之序數值的字串,而不是整數。The example also defines a WeekOfMonth enumeration to display a string that represents the ordinal value of the Week property rather than an integer.

private enum WeekOfMonth
{
   First = 1,
   Second = 2,
   Third = 3,
   Fourth = 4,
   Last = 5
}

private void GetFloatingTransitionTimes()
{
   ReadOnlyCollection<TimeZoneInfo> timeZones = TimeZoneInfo.GetSystemTimeZones();
   foreach (TimeZoneInfo zone in timeZones)
   {
      TimeZoneInfo.AdjustmentRule[] adjustmentRules = zone.GetAdjustmentRules();
      DateTimeFormatInfo dateInfo = CultureInfo.CurrentCulture.DateTimeFormat;
      foreach (TimeZoneInfo.AdjustmentRule adjustmentRule in adjustmentRules)
      {
         TimeZoneInfo.TransitionTime daylightStart = adjustmentRule.DaylightTransitionStart;
         if (! daylightStart.IsFixedDateRule)
            Console.WriteLine("{0}, {1:d}-{2:d}: Begins at {3:t} on the {4} {5} of {6}.", 
                              zone.StandardName, 
                              adjustmentRule.DateStart, 
                              adjustmentRule.DateEnd,                                 
                              daylightStart.TimeOfDay, 
                              ((WeekOfMonth)daylightStart.Week).ToString(),  
                              daylightStart.DayOfWeek.ToString(),
                              dateInfo.GetMonthName(daylightStart.Month));

         TimeZoneInfo.TransitionTime daylightEnd = adjustmentRule.DaylightTransitionEnd;
         if (! daylightEnd.IsFixedDateRule)
            Console.WriteLine("{0}, {1:d}-{2:d}: Ends at {3:t} on the {4} {5} of {6}.", 
                              zone.StandardName, 
                              adjustmentRule.DateStart, 
                              adjustmentRule.DateEnd,                                 
                              daylightEnd.TimeOfDay, 
                              ((WeekOfMonth)daylightEnd.Week).ToString(),  
                              daylightEnd.DayOfWeek.ToString(), 
                              dateInfo.GetMonthName(daylightEnd.Month));
      }
   }   
}
Private Enum WeekOfMonth As Integer
   First = 1
   Second = 2
   Third = 3
   Fourth = 4
   Last = 5 
End Enum

Private Sub GetFloatingTransitionTimes()
   Dim timeZones As ReadOnlyCollection(Of TimeZoneInfo) = TimeZoneInfo.GetSystemTimeZones()
   For Each zone As TimeZoneInfo In timeZones
      Dim adjustmentRules() As TimeZoneInfo.AdjustmentRule = zone.GetAdjustmentRules()
      For Each adjustmentRule As TimeZoneInfo.AdjustmentRule in adjustmentRules
         Dim daylightStart As TimeZoneInfo.TransitionTime = adjustmentRule.DaylightTransitionStart
         If Not daylightStart.IsFixedDateRule Then
            Console.WriteLine("{0}, {1:d}-{2:d}: Begins at {3:t} on the {4} {5} of {6}.", _
                              zone.StandardName, _
                              adjustmentRule.DateStart, _
                              adjustmentRule.DateEnd, _                                 
                              daylightStart.TimeOfDay, _
                              CType(daylightStart.Week, WeekOfMonth).ToString(), _ 
                              daylightStart.DayOfWeek.ToString(), _
                              MonthName(daylightStart.Month))
         End If
         Dim daylightEnd As TimeZoneInfo.TransitionTime = adjustmentRule.DaylightTransitionEnd
         If Not daylightEnd.IsFixedDateRule Then
            Console.WriteLine("{0}, {1:d}-{2:d}: Ends at {3:t} on the {4} {5} of {6}.", _
                              zone.StandardName, _
                              adjustmentRule.DateStart, _
                              adjustmentRule.DateEnd, _                                 
                              daylightEnd.TimeOfDay, _
                              CType(daylightEnd.Week, WeekOfMonth).ToString(), _ 
                              daylightEnd.DayOfWeek.ToString(), _
                              MonthName(daylightEnd.Month))
         End If   
      Next
   Next   
End Sub

備註

Week屬性的值僅用於具有浮動日期規則的時間變更。The value of the Week property is used only for time changes with floating-date rules. 有效值的範圍可以從1到5。Valid values can range from 1 to 5.

Month屬性會定義發生時間變更的月份。The Month property defines the month in which the time change occurs. Week屬性會決定轉換發生的周。The Week property determines the week on which the transition occurs. DayOfWeek屬性會定義轉換發生的星期幾。The DayOfWeek property defines the day of the week on which the transition occurs. Week屬性的值取決於下表所示。The value of the Week property is determined as shown in the following table.

如果周屬性值為If the Week property value is 轉換發生于The transition occurs on
11 DayOfWeekMonth第一次出現的值。The first occurrence of the DayOfWeek value in Month.
22 DayOfWeekMonth的第二個出現的值。The second occurrence of the DayOfWeek value in Month.
33 DayOfWeekMonth的第三個出現的值。The third occurrence of the DayOfWeek value in Month.
44 DayOfWeekMonth的第四個出現的值。The fourth occurrence of the DayOfWeek value in Month.
55 DayOfWeekMonth的最後一次出現的值。The last occurrence of the DayOfWeek value in Month.

例如,如果轉換發生在三月份的第一個星期日,則Week屬性的值為1。For example, if a transition occurs on the first Sunday of March, the value of the Week property is 1. 如果它發生在三月份的最後一個星期日,則Week屬性的值為5。If it occurs on the last Sunday of March, the value of the Week property is 5.

適用於

另請參閱