TimeZoneInfo.AdjustmentRule.DateStart TimeZoneInfo.AdjustmentRule.DateStart TimeZoneInfo.AdjustmentRule.DateStart TimeZoneInfo.AdjustmentRule.DateStart Property

定义

获取调整规则生效的日期。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

属性值

一个 DateTime 值,该值指示调整规则生效的日期。A DateTime value that indicates when the adjustment rule takes effect.

示例

下面的示例显示有关在本地计算机的系统注册表中定义的所有时区的信息, 包括其调整规则的开始日期和结束日期。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.

注解

DateStart属性的值是一个不包含时间部分的日期值。The value of the DateStart property is a date value without a time component. 它定义特定调整规则生效的日期。It defines the date on which a particular adjustment rule goes into effect. 这是一组转换 (通常由一个转换为夏令时, 一次转换为标准时间) 生效的日期。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. 例如, 调整规则可能会在2017年1月1日生效, 这将为三月的第二个星期日转换到夏令时, 并在11月第一个星期日转换回标准时间。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. 请注意, 调整规则的开始日期不会与第一个转换的日期相关联。Note that the starting date of the adjustment rule is not tied to the date of the first transition.

您可以在DateTime.MinValue.Date创建自DateEnd定义调整规则时分配给该属性, 以便在不需要使用历史时区信息的时区感知应用程序中使用。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.

重要

除非有一个令人信服的理由, 否则应将调整规则的开始日期定义为在时区遵循标准时间的时间间隔内发生。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. 除非有一个令人信服的理由, 否则不应将调整规则的开始日期定义为在时区采用夏令时的时间间隔内发生。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. 例如, 如果时区的夏令时从夏时制过渡到三月份的第三个星期日, 并将其转换为夏令时, 则在10月的第一个星期日发生, 调整规则的有效开始日期不应为特定年份, 因为该日期出现在夏时制期间。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.

默认情况下, Windows XP 中的注册表定义一个调整规则, 其开始日期为每个时区的0001年1月 1 DateTime.MinValue.Date日星期一 (的值)。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. 对于美国中的时区, Windows Vista 中的注册表定义了两个调整规则:For time zones in the United States, the registry in Windows Vista defines two adjustment rules:

  • 0001年1月1日星期一至星期日, 2006 年12月31日。Monday, January 01, 0001, to Sunday, December 31, 2006.

  • 2007年1月31日, 星期一至星期五, 9999, 星期五。Monday, January 01, 2007, to Friday, December 31, 9999.

这意味着, 尽管注册表中存储的时区调整规则对于执行当前时区相关操作非常有用, 但无法可靠地用于检索历史时区信息。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. 有关使用可在历史时区感知应用程序中使用的多个调整规则定义自定义时区的信息, 请参阅如何:创建具有调整规则的时区。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.

适用于