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.

如果 Week 属性值为If the Week property value is 转换发生于The transition occurs on
11 MonthDayOfWeek 值的第一个匹配项。The first occurrence of the DayOfWeek value in Month.
22 MonthDayOfWeek 值的第二个匹配项。The second occurrence of the DayOfWeek value in Month.
33 MonthDayOfWeek 值的第三个匹配项。The third occurrence of the DayOfWeek value in Month.
44 MonthDayOfWeek 值的第四个匹配项。The fourth occurrence of the DayOfWeek value in Month.
55 MonthDayOfWeek 值的最后一个匹配项。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. 如果它发生在3月的最后一个星期日,则 Week 属性的值为5。If it occurs on the last Sunday of March, the value of the Week property is 5.

适用于

另请参阅