TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule(DateTime, DateTime, TimeSpan, TimeZoneInfo+TransitionTime, TimeZoneInfo+TransitionTime) TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule(DateTime, DateTime, TimeSpan, TimeZoneInfo+TransitionTime, TimeZoneInfo+TransitionTime) TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule(DateTime, DateTime, TimeSpan, TimeZoneInfo+TransitionTime, TimeZoneInfo+TransitionTime) TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule(DateTime, DateTime, TimeSpan, TimeZoneInfo+TransitionTime, TimeZoneInfo+TransitionTime) Method

定义

为特定时区创建新调整规则。Creates a new adjustment rule for a particular time zone.

public:
 static TimeZoneInfo::AdjustmentRule ^ CreateAdjustmentRule(DateTime dateStart, DateTime dateEnd, TimeSpan daylightDelta, TimeZoneInfo::TransitionTime daylightTransitionStart, TimeZoneInfo::TransitionTime daylightTransitionEnd);
public static TimeZoneInfo.AdjustmentRule CreateAdjustmentRule (DateTime dateStart, DateTime dateEnd, TimeSpan daylightDelta, TimeZoneInfo.TransitionTime daylightTransitionStart, TimeZoneInfo.TransitionTime daylightTransitionEnd);
static member CreateAdjustmentRule : DateTime * DateTime * TimeSpan * TimeZoneInfo.TransitionTime * TimeZoneInfo.TransitionTime -> TimeZoneInfo.AdjustmentRule
Public Shared Function CreateAdjustmentRule (dateStart As DateTime, dateEnd As DateTime, daylightDelta As TimeSpan, daylightTransitionStart As TimeZoneInfo.TransitionTime, daylightTransitionEnd As TimeZoneInfo.TransitionTime) As TimeZoneInfo.AdjustmentRule

参数

dateStart
DateTime DateTime DateTime DateTime

调整规则的生效日期。The effective date of the adjustment rule. 如果 dateStart 参数的值为 DateTime.MinValue.Date,那么这是时区的第一个有效的调整规则。If the value of the dateStart parameter is DateTime.MinValue.Date, this is the first adjustment rule in effect for a time zone.

dateEnd
DateTime DateTime DateTime DateTime

执行调整规则的最后日期。The last date that the adjustment rule is in force. 如果 dateEnd 参数的值为 DateTime.MaxValue.Date,则调整规则无结束日期。If the value of the dateEnd parameter is DateTime.MaxValue.Date, the adjustment rule has no end date.

daylightDelta
TimeSpan TimeSpan TimeSpan TimeSpan

调整所产生的时间更改。The time change that results from the adjustment. 将该值添加到时区的 BaseUtcOffset 属性,以便获取从协调世界时 (UTC) 开始的正确的夏令时偏移量。This value is added to the time zone's BaseUtcOffset property to obtain the correct daylight offset from Coordinated Universal Time (UTC). 该值的范围介于 -14 到 14。This value can range from -14 to 14.

daylightTransitionStart
TimeZoneInfo.TransitionTime TimeZoneInfo.TransitionTime TimeZoneInfo.TransitionTime TimeZoneInfo.TransitionTime

定义夏令时的开始时间的对象。An object that defines the start of daylight saving time.

daylightTransitionEnd
TimeZoneInfo.TransitionTime TimeZoneInfo.TransitionTime TimeZoneInfo.TransitionTime TimeZoneInfo.TransitionTime

定义夏令时的结束时间的对象。An object that defines the end of daylight saving time.

返回

表示新调整规则的对象。An object that represents the new adjustment rule.

异常

参数 dateStartdateEnd 的属性 Kind 的值不等于 UnspecifiedThe Kind property of the dateStart or dateEnd parameter does not equal Unspecified.

-or- daylightTransitionStart 参数等于 daylightTransitionEnd 参数。The daylightTransitionStart parameter is equal to the daylightTransitionEnd parameter.

-or- dateStartdateEnd 参数包含一个日期的时间值。The dateStart or dateEnd parameter includes a time of day value.

dateEnd 早于 dateStartdateEnd is earlier than dateStart.

-or- daylightDelta 小于 -14 或大于 14。daylightDelta is less than -14 or greater than 14.

-or- daylightDelta 参数的 Milliseconds 属性不等于 0。The Milliseconds property of the daylightDelta parameter is not equal to 0.

-or- daylightDelta 参数的 Ticks 属性不等于整秒数。The Ticks property of the daylightDelta parameter does not equal a whole number of seconds.

示例

下面的示例创建一个备用中心标准时区, 并为1976-1986、1987-2006、2007和及更高版本定义三个调整规则。The following example creates an alternate Central Standard Time zone and defines three adjustment rules for the periods 1976-1986, 1987-2006, and 2007 and beyond. 这些规则将添加到一个泛型List<T>对象中, 然后将其元素复制TimeZoneInfo.AdjustmentRule到数组中。These rules are added to a generic List<T> object whose elements are then copied to a TimeZoneInfo.AdjustmentRule array. 然后, 在调用TimeZoneInfo.CreateCustomTimeZone(String, TimeSpan, String, String, String, TimeZoneInfo+AdjustmentRule[])方法时使用此数组。This array is then used in the call to the TimeZoneInfo.CreateCustomTimeZone(String, TimeSpan, String, String, String, TimeZoneInfo+AdjustmentRule[]) method.

// Create alternate Central Standard Time to include historical time zone information
//
// Declare necessary TimeZoneInfo.AdjustmentRule objects for time zone
TimeSpan delta = new TimeSpan(1, 0, 0);
TimeZoneInfo.AdjustmentRule adjustment;
List<TimeZoneInfo.AdjustmentRule> adjustmentList = new List<TimeZoneInfo.AdjustmentRule>();
// Declare transition time variables to hold transition time information
TimeZoneInfo.TransitionTime transitionRuleStart, transitionRuleEnd;

// Define end rule (for 1976-2006)
transitionRuleEnd = TimeZoneInfo.TransitionTime.CreateFloatingDateRule(new DateTime(1, 1, 1, 2, 0, 0), 10, 5, DayOfWeek.Sunday);
// Define rule (1976-1986)
transitionRuleStart = TimeZoneInfo.TransitionTime.CreateFloatingDateRule(new DateTime(1, 1, 1, 2, 0, 0), 04, 05, DayOfWeek.Sunday);
adjustment = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule(new DateTime(1976, 1, 1), new DateTime(1986, 12, 31), delta, transitionRuleStart, transitionRuleEnd);
adjustmentList.Add(adjustment);
// Define rule (1987-2006)  
transitionRuleStart = TimeZoneInfo.TransitionTime.CreateFloatingDateRule(new DateTime(1, 1, 1, 2, 0, 0), 04, 01, DayOfWeek.Sunday);
adjustment = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule(new DateTime(1987, 1, 1), new DateTime(2006, 12, 31), delta, transitionRuleStart, transitionRuleEnd);
adjustmentList.Add(adjustment);
// Define rule (2007- )  
transitionRuleStart = TimeZoneInfo.TransitionTime.CreateFloatingDateRule(new DateTime(1, 1, 1, 2, 0, 0), 03, 02, DayOfWeek.Sunday);
transitionRuleEnd = TimeZoneInfo.TransitionTime.CreateFloatingDateRule(new DateTime(1, 1, 1, 2, 0, 0), 11, 01, DayOfWeek.Sunday);
adjustment = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule(new DateTime(2007, 01, 01), DateTime.MaxValue.Date, delta, transitionRuleStart, transitionRuleEnd);
adjustmentList.Add(adjustment);
              
// Create custom U.S. Central Standard Time zone         
TimeZoneInfo.CreateCustomTimeZone("Central Standard Time", new TimeSpan(-6, 0, 0), 
                "(GMT-06:00) Central Time (US Only)", "Central Standard Time", 
                "Central Daylight Time", adjustmentList.ToArray());       
' Create alternate Central Standard Time to include historical time zone information
'
' Declare necessary TimeZoneInfo.AdjustmentRule objects for time zone
Dim delta As New TimeSpan(1, 0, 0)
Dim adjustment As TimeZoneInfo.AdjustmentRule
Dim adjustmentList As New List(Of TimeZoneInfo.AdjustmentRule)
' Declare transition time variables to hold transition time information
Dim transitionRuleStart, transitionRuleEnd As TimeZoneInfo.TransitionTime

' Define end rule (for 1976-2006)
transitionRuleEnd = TimeZoneInfo.TransitionTime.CreateFloatingDateRule(#02:00:00AM#, 10, 5, DayOfWeek.Sunday)
' Define rule (1976-1986)
transitionRuleStart = TimeZoneInfo.TransitionTime.CreateFloatingDateRule(#2:00:00AM#, 04, 05, DayOfWeek.Sunday)
adjustment = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule(#01/01/1976#, #12/31/1986#, delta, transitionRuleStart, transitionRuleEnd)
adjustmentList.Add(adjustment)
' Define rule (1987-2006)  
transitionRuleStart = TimeZoneInfo.TransitionTime.CreateFloatingDateRule(#2:00:00AM#, 04, 01, DayOfWeek.Sunday)
adjustment = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule(#01/01/1987#, #12/31/2006#, delta, transitionRuleStart, transitionRuleEnd)
adjustmentList.Add(adjustment)
' Define rule (2007- )  
transitionRuleStart = TimeZoneInfo.TransitionTime.CreateFloatingDateRule(#2:00:00AM#, 03, 02, DayOfWeek.Sunday)
transitionRuleEnd = TimeZoneInfo.TransitionTime.CreateFloatingDateRule(#2:00:00AM#, 11, 01, DayOfWeek.Sunday)
adjustment = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule(#01/01/2007#, Date.MaxValue.Date, delta, transitionRuleStart, transitionRuleEnd)
adjustmentList.Add(adjustment)
              
' Create custom U.S. Central Standard Time Zone
TimeZoneInfo.CreateCustomTimeZone("Central Standard Time", New TimeSpan(-6, 0, 0), _
                "(GMT-06:00) Central Time (US Only)", "Central Standard Time", _
                "Central Daylight Time", adjustmentList.ToArray())     

注解

您可以使用此方法为自定义时区创建一个或多个调整规则。You can use this method to create one or more adjustment rules for a custom time zone. 然后, 可以将TimeZoneInfo.AdjustmentRule对此方法的调用返回的对象数组adjustmentRules作为参数传递给该CreateCustomTimeZone方法的两个重载。An array of the TimeZoneInfo.AdjustmentRule objects returned by calls to this method can then be passed as the adjustmentRules parameter to two overloads of the CreateCustomTimeZone method. 该示例演示了此过程。The example illustrates this procedure.

备注

CreateAdjustmentRule方法只能用于定义新时区的调整规则; 它不能用于修改现有时区的调整规则。The CreateAdjustmentRule method can be used only to define an adjustment rule for a new time zone; it cannot be used to modify an adjustment rule for an existing time zone.

和参数必须是不包含时间部分的日期值或ArgumentException引发。 dateEnd dateStartThe dateStart and dateEnd parameters must be date values without a time component or an ArgumentException is thrown. 可以通过从日期和时间的DateTime Date属性检索值来删除时间组成部分, 如以下语句所示:The time component can be removed by retrieving a DateTime value from the date and time's Date property as shown in the following statements:

DateTime.MinValue.Date  
DateTime.MaxValue.Date  
DateTime.Now.Date   
dateVariable.Date  

和参数的属性还必须是DateTimeKind.UnspecifiedKind dateStart dateEndThe Kind property of the dateStart and dateEnd parameters must also be DateTimeKind.Unspecified.

daylightDelta参数的值可以介于-14 到14之间。The value of the daylightDelta parameter can range from -14 to 14. daylightDelta baseUtcOffset InvalidTimeZoneException在对方法的调用中使用的参数和参数的总和还必须介于-14到14之间,否则将引发。TimeZoneInfo.CreateCustomTimeZoneThe sum of the daylightDelta parameter and the baseUtcOffset parameter used in the call to the TimeZoneInfo.CreateCustomTimeZone method must also range from -14 to 14 or an InvalidTimeZoneException is thrown.

备注

daylightDelta参数定义时区的标准时间与夏时制之间的时差。The daylightDelta parameter defines the difference between a time zone's standard time and its daylight saving time. 它不用于定义时区的标准时间与协调世界时 (UTC) 的偏移量。It is not intended to define the time zone's standard time offset from Coordinated Universal Time (UTC). TimeZoneInfo类假设此偏移量在时区的整个生存期内都是常量。The TimeZoneInfo class assumes that this offset from UTC is constant throughout the life of the time zone. 若要反映时区与 UTC 的偏移量发生的更改, 而不是由应用调整规则引起的, 则必须使用CreateCustomTimeZone方法创建新的自定义时区。To reflect a change in a time zone's offset from UTC that is not caused by the application of an adjustment rule, you must use the CreateCustomTimeZone method to create a new custom time zone.

适用于