Прочетете на английски Редактиране

Споделяне чрез


TimeZoneInfo.TransitionTime.Week Property

Definition

Gets the week of the month in which a time change occurs.

C#
public int Week { get; }

Property Value

The week of the month in which the time change occurs.

Examples

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. The example also defines a WeekOfMonth enumeration to display a string that represents the ordinal value of the Week property rather than an integer.

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

Remarks

The value of the Week property is used only for time changes with floating-date rules. Valid values can range from 1 to 5.

The Month property defines the month in which the time change occurs. The Week property determines the week on which the transition occurs. The DayOfWeek property defines the day of the week on which the transition occurs. The value of the Week property is determined as shown in the following table.

If the Week property value is The transition occurs on
1 The first occurrence of the DayOfWeek value in Month.
2 The second occurrence of the DayOfWeek value in Month.
3 The third occurrence of the DayOfWeek value in Month.
4 The fourth occurrence of the DayOfWeek value in Month.
5 The last occurrence of the DayOfWeek value in Month.

For example, if a transition occurs on the first Sunday of March, the value of the Week property is 1. If it occurs on the last Sunday of March, the value of the Week property is 5.

Applies to

Продукт Версии
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.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, 4.8.1
.NET Standard 2.0, 2.1

See also