TimeZoneInfo.AdjustmentRule.DateStart Propriedade

Definição

Obtém a data em que a regra de ajuste entra em vigor.Gets the date when the adjustment rule takes effect.

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

Valor da propriedade

DateTime

Um DateTime valor que indica quando a regra de ajuste entra em vigor.A DateTime value that indicates when the adjustment rule takes effect.

Exemplos

O exemplo a seguir exibe informações sobre todos os fusos horários definidos no registro do sistema do computador local, incluindo as datas de início e término de suas regras de ajuste.The following example displays information about all of the time zones defined in the local computer's system registry, including the starting and ending dates of their adjustment rules.

using System;
using System.Collections.ObjectModel;
using System.Globalization;

public class Example
{
   public static void Main()
   {
      ReadOnlyCollection<TimeZoneInfo> timeZones = TimeZoneInfo.GetSystemTimeZones();
      DateTimeFormatInfo dateInfo = CultureInfo.CurrentCulture.DateTimeFormat;
      
      foreach (var zone in timeZones)
      {
         Console.WriteLine("{0} transition time information:", zone.StandardName);
         Console.WriteLine("   Time zone information: ");
         Console.WriteLine("      Base UTC Offset: {0}", zone.BaseUtcOffset);
         Console.WriteLine("      Supports DST: {0}", zone.SupportsDaylightSavingTime);

         TimeZoneInfo.AdjustmentRule[] adjustmentRules= zone.GetAdjustmentRules();
         
         // Indicate that time zone has no adjustment rules
         if (adjustmentRules.Length == 0) {
            Console.WriteLine("      No adjustment rules defined.");
         }   
         else {
            Console.WriteLine("      Adjustment Rules: {0}", adjustmentRules.Length);
            // Iterate adjustment rules       
            foreach (var adjustmentRule in adjustmentRules) {
               Console.WriteLine("   Adjustment rule from {0:d} to {1:d}:", 
                                 adjustmentRule.DateStart, 
                                 adjustmentRule.DateEnd);                                 
               Console.WriteLine("      Delta: {0}", adjustmentRule.DaylightDelta);
               // Get start of transition
               TimeZoneInfo.TransitionTime daylightStart = adjustmentRule.DaylightTransitionStart;
               // Display information on floating date rule
               if (! daylightStart.IsFixedDateRule)
                  Console.WriteLine("      Begins at {0:t} on the {1} {2} of {3}", 
                                 daylightStart.TimeOfDay, 
                                 (WeekOfMonth) daylightStart.Week,  
                                 daylightStart.DayOfWeek, 
                                 dateInfo.GetMonthName(daylightStart.Month));
               // Display information on fixed date rule 
               else
                  Console.WriteLine("      Begins at {0:t} on {1} {2}", 
                                    daylightStart.TimeOfDay, 
                                    dateInfo.GetMonthName(daylightStart.Month), 
                                    daylightStart.Day);
               
               // Get end of transition.
              TimeZoneInfo.TransitionTime daylightEnd = adjustmentRule.DaylightTransitionEnd;
               // Display information on floating date rule.
               if (!daylightEnd.IsFixedDateRule) 
                  Console.WriteLine("      Ends at {0:t} on the {1} {2} of {3}", 
                                 daylightEnd.TimeOfDay, 
                                 (WeekOfMonth) daylightEnd.Week,  
                                 daylightEnd.DayOfWeek, 
                                 dateInfo.GetMonthName(daylightEnd.Month));
               // Display information on fixed date rule.
               else
                  Console.WriteLine("      Ends at {0:t} on {1} {2}", 
                                    daylightEnd.TimeOfDay, 
                                    dateInfo.GetMonthName(daylightEnd.Month), 
                                    daylightEnd.Day);
            }
         }   
      }   
   }

   private enum WeekOfMonth 
   {
      First = 1,
      Second = 2,
      Third = 3,
      Fourth = 4,
      Last = 5,
   }
}
// A portion of the output from the example might appear as follows:
//       Tonga Standard Time transition time information:
//          Time zone information:
//             Base UTC Offset: 13:00:00
//             Supports DST: False
//             No adjustment rules defined.
//       Samoa Standard Time transition time information:
//          Time zone information:
//             Base UTC Offset: 13:00:00
//             Supports DST: True
//             Adjustment Rules: 4
//          Adjustment rule from 1/1/0001 to 12/31/2009:
//             Delta: 00:00:00
//             Begins at 12:00 AM on January 1
//             Ends at 12:00 AM on January 1
//          Adjustment rule from 1/1/2010 to 12/31/2010:
//             Delta: 01:00:00
//             Begins at 11:59 PM on the Last Saturday of September
//             Ends at 12:00 AM on the First Friday of January
//          Adjustment rule from 1/1/2011 to 12/31/2011:
//             Delta: 01:00:00
//             Begins at 3:00 AM on the Fourth Saturday of September
//             Ends at 4:00 AM on the First Saturday of April
//          Adjustment rule from 1/1/2012 to 12/31/9999:
//             Delta: 01:00:00
//             Begins at 12:00 AM on the Last Sunday of September
//             Ends at 1:00 AM on the First Sunday of April
//       Line Islands Standard Time transition time information:
//          Time zone information:
//             Base UTC Offset: 14:00:00
//             Supports DST: False
//             No adjustment rules defined.
Imports System.Collections.ObjectModel
Imports System.Globalization

Module Example
   Public Sub Main()
      Dim timeZones As ReadOnlyCollection(Of TimeZoneInfo) = TimeZoneInfo.GetSystemTimeZones()
      Dim dateInfo As DateTimeFormatInfo = CultureInfo.CurrentCulture.DateTimeFormat
      
      For Each zone In timeZones
         Console.WriteLine("{0} transition time information:", zone.StandardName)
         Console.WriteLine("   Time zone information: ")
         Console.WriteLine("      Base UTC Offset: {0}", zone.BaseUtcOffset)
         Console.WriteLine("      Supports DST: {0}", zone.SupportsDaylightSavingTime)

         Dim adjustmentRules() As TimeZoneInfo.AdjustmentRule = zone.GetAdjustmentRules()
         
         ' Indicate that time zone has no adjustment rules
         If adjustmentRules.Length = 0 Then
            Console.WriteLine("      No adjustment rules defined.")
         Else
            Console.WriteLine("      Adjustment Rules: {0}", adjustmentRules.Length)
            ' Iterate adjustment rules       
            For Each adjustmentRule In adjustmentRules
               Console.WriteLine("   Adjustment rule from {0:d} to {1:d}:", 
                                 adjustmentRule.DateStart, 
                                 adjustmentRule.DateEnd)                                 
               Console.WriteLine("      Delta: {0}", adjustmentRule.DaylightDelta)
               ' Get start of transition
               Dim daylightStart As TimeZoneInfo.TransitionTime = adjustmentRule.DaylightTransitionStart
               ' Display information on floating date rule
               If Not daylightStart.IsFixedDateRule Then
                  Console.WriteLine("      Begins at {0:t} on the {1} {2} of {3}", 
                                 daylightStart.TimeOfDay, 
                                 CType(daylightStart.Week, WeekOfMonth),  
                                 daylightStart.DayOfWeek, 
                                 dateInfo.GetMonthName(daylightStart.Month))
               ' Display information on fixed date rule 
               Else
                  Console.WriteLine("      Begins at {0:t} on {1} {2}", 
                                    daylightStart.TimeOfDay, 
                                    dateInfo.GetMonthName(daylightStart.Month), 
                                    daylightStart.Day)
               End If
               
               ' Get end of transition.
               Dim daylightEnd As TimeZoneInfo.TransitionTime = adjustmentRule.DaylightTransitionEnd
               ' Display information on floating date rule.
               If Not daylightEnd.IsFixedDateRule Then 
                  Console.WriteLine("      Ends at {0:t} on the {1} {2} of {3}", 
                                 daylightEnd.TimeOfDay, 
                                 CType(daylightEnd.Week, WeekOfMonth),  
                                 daylightEnd.DayOfWeek, 
                                 dateInfo.GetMonthName(daylightEnd.Month))
               ' Display information on fixed date rule.
               Else
                  Console.WriteLine("      Ends at {0:t} on {1} {2}", 
                                    daylightEnd.TimeOfDay, 
                                    dateInfo.GetMonthName(daylightEnd.Month), 
                                    daylightEnd.Day)
               End If
            Next
         End If   
      Next   
   End Sub

   Private Enum WeekOfMonth As Integer
      First = 1
      Second = 2
      Third = 3
      Fourth = 4
      Last = 5
   End Enum
End Module
' A portion of the output from the example might appear as follows:
'       Tonga Standard Time transition time information:
'          Time zone information:
'             Base UTC Offset: 13:00:00
'             Supports DST: False
'             No adjustment rules defined.
'       Samoa Standard Time transition time information:
'          Time zone information:
'             Base UTC Offset: 13:00:00
'             Supports DST: True
'             Adjustment Rules: 4
'          Adjustment rule from 1/1/0001 to 12/31/2009:
'             Delta: 00:00:00
'             Begins at 12:00 AM on January 1
'             Ends at 12:00 AM on January 1
'          Adjustment rule from 1/1/2010 to 12/31/2010:
'             Delta: 01:00:00
'             Begins at 11:59 PM on the Last Saturday of September
'             Ends at 12:00 AM on the First Friday of January
'          Adjustment rule from 1/1/2011 to 12/31/2011:
'             Delta: 01:00:00
'             Begins at 3:00 AM on the Fourth Saturday of September
'             Ends at 4:00 AM on the First Saturday of April
'          Adjustment rule from 1/1/2012 to 12/31/9999:
'             Delta: 01:00:00
'             Begins at 12:00 AM on the Last Sunday of September
'             Ends at 1:00 AM on the First Sunday of April
'       Line Islands Standard Time transition time information:
'          Time zone information:
'             Base UTC Offset: 14:00:00
'             Supports DST: False
'             No adjustment rules defined.

Comentários

O valor da DateStart propriedade é um valor de data sem um componente de hora.The value of the DateStart property is a date value without a time component. Ele define a data em que uma regra de ajuste específico entra em vigor.It defines the date on which a particular adjustment rule goes into effect. Essa é a data em que um conjunto de transições (que normalmente são definidas por uma transição para o horário de verão e uma transição de volta para o horário padrão) entram em vigor.This is the date in which a set of transitions (which typically are defined by one transition to daylight savings time and one transition back to standard time) go into effect. Por exemplo, uma regra de ajuste pode entrar em vigor em 1º de janeiro de 2017, que fornece uma transição para o horário de verão no segundo domingo de março e para uma transição de volta para o horário padrão no primeiro domingo de novembro.For example, an adjustment rule might go into effect on January 1, 2017, that provides for a transition to daylight savings time on the second Sunday of March and for a transition back to standard time on the first Sunday of November. Observe que a data de início da regra de ajuste não está vinculada à data da primeira transição.Note that the starting date of the adjustment rule is not tied to the date of the first transition.

Você pode atribuir DateTime.MinValue.Date à DateEnd propriedade ao criar uma regra de ajuste personalizado para uso em um aplicativo com reconhecimento de fuso horário que não precise trabalhar com informações históricas de fuso horário.You can assign DateTime.MinValue.Date to the DateEnd property when you create a custom adjustment rule for use in a time zone-aware application that does not have to work with historic time zone information.

Importante

A menos que haja um motivo convincente para fazer o contrário, você deve definir a data de início da regra de ajuste para ocorrer dentro do intervalo de tempo durante o qual o fuso horário observa o horário padrão.Unless there is a compelling reason to do otherwise, you should define the adjustment rule's start date to occur within the time interval during which the time zone observes standard time. A menos que haja um motivo convincente para fazer isso, você não deve definir a data de início da regra de ajuste para ocorrer dentro do intervalo de tempo durante o qual o fuso horário observa o horário de verão.Unless there is a compelling reason to do so, you should not define the adjustment rule's start date to occur within the time interval during which the time zone observes daylight saving time. Por exemplo, se a transição de um fuso horário do horário de verão ocorrer no terceiro domingo de março e sua transição para o horário de verão ocorrer no primeiro domingo de outubro, a data de início efetiva da regra de ajuste não deve ser 1 de janeiro de um ano específico, já que essa data ocorre dentro do período de horário de verão.For example, if a time zone's transition from daylight saving time occurs on the third Sunday of March and its transition to daylight saving time occurs on the first Sunday of October, the effective start date of the adjustment rule should not be January 1 of a particular year, since that date occurs within the period of daylight saving time.

Por padrão, o registro no Windows XP define uma única regra de ajuste cuja data de início é segunda-feira, janeiro de 01, 0001 (o valor de DateTime.MinValue.Date ), para cada fuso horário.By default, the registry in Windows XP defines a single adjustment rule whose start date is Monday, January 01, 0001 (the value of DateTime.MinValue.Date), for each time zone. Para os fusos horários no Estados Unidos, o registro no Windows Vista define duas regras de ajuste:For time zones in the United States, the registry in Windows Vista defines two adjustment rules:

  • Segunda-feira, 1º de janeiro de 0001 a domingo, 31 de dezembro de 2006.Monday, January 01, 0001, to Sunday, December 31, 2006.

  • Segunda-feira, 1º de janeiro de 2007 a sexta-feira, 31 de dezembro de 9999.Monday, January 01, 2007, to Friday, December 31, 9999.

Isso significa que, embora as regras de ajuste de fuso horário armazenadas no registro sejam úteis para a execução de operações atuais relacionadas a fuso horário, elas não podem ser usadas de forma confiável para recuperar informações históricas de fuso horário.This means that, although time zone adjustment rules stored in the registry are useful for performing current time zone-related operations, they cannot be reliably used for retrieving historical time zone information. Para obter informações sobre como definir um fuso horário personalizado com várias regras de ajuste que podem ser usadas em um aplicativo de reconhecimento de fuso horário histórico, consulte como: criar fusos horários com regras de ajuste.For information about defining a custom time zone with multiple adjustment rules that can be used in a historical time zone-aware application, see How to: Create Time Zones with Adjustment Rules.

Aplica-se a