Partilhar via


TimeZoneInfo.TransitionTime.DayOfWeek Propriedade

Definição

Obtém o dia da semana no qual ocorrerá a alteração de hora.

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

Valor da propriedade

O dia da semana no qual ocorrerá a alteração de hora.

Exemplos

O exemplo a seguir enumera os fusos horários encontrados no computador local e exibe informações de tempo de transição para todas as transições de data flutuante. As informações de hora incluem o dia da semana em que a alteração de hora ocorre.

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

let getFloatingTransitionTimes () =
    let timeZones = TimeZoneInfo.GetSystemTimeZones()
    for zone in timeZones do
        let adjustmentRules = zone.GetAdjustmentRules()
        let dateInfo = CultureInfo.CurrentCulture.DateTimeFormat
        for adjustmentRule in adjustmentRules do
            let daylightStart = adjustmentRule.DaylightTransitionStart
            if not daylightStart.IsFixedDateRule then
                printfn $"{zone.StandardName}, {adjustmentRule.DateStart:d}-{adjustmentRule.DateEnd:d}: Begins at {daylightStart.TimeOfDay:t} on the {enum<WeekOfMonth> daylightStart.Week} {daylightStart.DayOfWeek} of {dateInfo.GetMonthName daylightStart.Month}." 
            
            let daylightEnd = adjustmentRule.DaylightTransitionEnd
            if not daylightEnd.IsFixedDateRule then
                printfn $"{zone.StandardName}, {adjustmentRule.DateStart:d}-{adjustmentRule.DateEnd:d}: Ends at {daylightEnd.TimeOfDay:t} on the {enum<WeekOfMonth> daylightEnd.Week} {daylightEnd.DayOfWeek} of {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

Comentários

A DayOfWeek propriedade retornará um valor válido somente se a IsFixedDateRule propriedade for false.

A DayOfWeek propriedade indica o dia da semana em que uma regra de data flutuante é aplicada (por exemplo, o segundo domingo de novembro). Por outro lado, a Day propriedade indica o dia do mês em que uma regra de data fixa é aplicada (por exemplo, 15 de abril).

Aplica-se a