TimeZoneInfo.TransitionTime.CreateFloatingDateRule 方法

定义

定义一个使用浮动日期规则的日期更改(即,发生在特定月份的特定星期的特定星期几的时间更改)。

public:
 static TimeZoneInfo::TransitionTime CreateFloatingDateRule(DateTime timeOfDay, int month, int week, DayOfWeek dayOfWeek);
public static TimeZoneInfo.TransitionTime CreateFloatingDateRule (DateTime timeOfDay, int month, int week, DayOfWeek dayOfWeek);
static member CreateFloatingDateRule : DateTime * int * int * DayOfWeek -> TimeZoneInfo.TransitionTime
Public Shared Function CreateFloatingDateRule (timeOfDay As DateTime, month As Integer, week As Integer, dayOfWeek As DayOfWeek) As TimeZoneInfo.TransitionTime

参数

timeOfDay
DateTime

发生时间更改的时间。 此参数对应于 TimeOfDay 属性。

month
Int32

发生时间更改的月份。 此参数对应于 Month 属性。

week
Int32

时间更改发生在月中的第几个星期。 它的值的范围是从 1 到 5,其中 5 表示该月的最后一周。 此参数对应于 Week 属性。

dayOfWeek
DayOfWeek

时间更改发生在星期几。 此参数对应于 DayOfWeek 属性。

返回

TimeZoneInfo.TransitionTime

有关时间更改的数据。

例外

timeOfDay 参数具有非默认的日期组件。

  • 或 - timeOfDay 参数不表示整毫秒数。

  • 或 - timeOfDay 参数的 Kind 属性不是 Unspecified

month 小于 1 或大于 12。

  • 或 - week 小于 1 或大于 5。

  • 或 - dayOfWeek 参数不是 DayOfWeek 枚举的成员。

示例

以下示例使用固定日期规则和浮点日期规则为虚构时区创建时区转换。 浮动日期规则定义从凌晨 2:00 开始的时区调整。 3月的最后一个星期天结束,上午3:00结束。 1956年10月的第四个星期天。

// Declare necessary TimeZoneInfo.AdjustmentRule objects for time zone
TimeZoneInfo imaginaryTZ;
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 a fictitious new time zone consisting of fixed and floating adjustment rules 
// Define fixed rule (for 1900-1955)
transitionRuleStart = TimeZoneInfo.TransitionTime.CreateFixedDateRule(new DateTime(1, 1, 1, 2, 0, 0), 3, 15);
transitionRuleEnd = TimeZoneInfo.TransitionTime.CreateFixedDateRule(new DateTime(1, 1, 1, 3, 0, 0), 11, 15);
adjustment = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule(new DateTime(1900, 1, 1), new DateTime(1955, 12, 31), 
             delta, transitionRuleStart, transitionRuleEnd);
adjustmentList.Add(adjustment);
// Define floating rule (for 1956- )
transitionRuleStart = TimeZoneInfo.TransitionTime.CreateFloatingDateRule(new DateTime(1, 1, 1, 2, 0, 0), 3, 5, DayOfWeek.Sunday);
transitionRuleEnd = TimeZoneInfo.TransitionTime.CreateFloatingDateRule(new DateTime(1, 1, 1, 3, 0, 0), 10, 4, DayOfWeek.Sunday); 
adjustment = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule(new DateTime(1956, 1, 1), DateTime.MaxValue.Date, delta, transitionRuleStart, transitionRuleEnd);
adjustmentList.Add(adjustment); 

// Create fictitious time zone   
imaginaryTZ = TimeZoneInfo.CreateCustomTimeZone("Fictitious Standard Time", new TimeSpan(-9, 0, 0), 
                "(GMT-09:00) Fictitious Time", "Fictitious Standard Time", 
                "Fictitious Daylight Time", adjustmentList.ToArray());
let delta = TimeSpan(1, 0, 0)
let adjustmentList = ResizeArray()
                    
// Define a fictitious new time zone consisting of fixed and floating adjustment rules 
// Define fixed rule (for 1900-1955)
let transitionRuleStart = TimeZoneInfo.TransitionTime.CreateFixedDateRule(DateTime(1, 1, 1, 2, 0, 0), 3, 15)
let transitionRuleEnd = TimeZoneInfo.TransitionTime.CreateFixedDateRule(DateTime(1, 1, 1, 3, 0, 0), 11, 15)
let adjustment = 
    TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule(DateTime(1900, 1, 1), DateTime(1955, 12, 31), delta, transitionRuleStart, transitionRuleEnd)
adjustmentList.Add adjustment
// Define floating rule (for 1956- )
let transitionRuleStart = TimeZoneInfo.TransitionTime.CreateFloatingDateRule(DateTime(1, 1, 1, 2, 0, 0), 3, 5, DayOfWeek.Sunday)
let transitionRuleEnd = TimeZoneInfo.TransitionTime.CreateFloatingDateRule(DateTime(1, 1, 1, 3, 0, 0), 10, 4, DayOfWeek.Sunday) 
let adjustment = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule(DateTime(1956, 1, 1), DateTime.MaxValue.Date, delta, transitionRuleStart, transitionRuleEnd)
adjustmentList.Add adjustment 

// Create fictitious time zone   
let imaginaryTZ = 
    TimeZoneInfo.CreateCustomTimeZone("Fictitious Standard Time", TimeSpan(-9, 0, 0), 
                "(GMT-09:00) Fictitious Time", "Fictitious Standard Time", 
                "Fictitious Daylight Time", adjustmentList.ToArray())
' Declare necessary TimeZoneInfo.AdjustmentRule objects for time zone
Dim imaginaryTZ As TimeZoneInfo
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 a fictitious new time zone consisting of fixed and floating adjustment rules 
' Define fixed rule (for 1900-1955)
transitionRuleStart = TimeZoneInfo.TransitionTime.CreateFixedDateRule(#2:00:00AM#, 3, 15)
transitionRuleEnd = TimeZoneInfo.TransitionTime.CreateFixedDateRule(#3:00:00AM#, 11, 15)
adjustment = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule(#1/1/1900#, #12/31/1955#, delta, _
             transitionRuleStart, transitionRuleEnd)
adjustmentList.Add(adjustment)
' Define floating rule (for 1956- )
transitionRuleStart = TimeZoneInfo.TransitionTime.CreateFloatingDateRule(#02:00:00AM#, 3, 5, DayOfWeek.Sunday)
transitionRuleEnd = TimeZoneInfo.TransitionTime.CreateFloatingDateRule(#03:00:00AM#, 10, 4, DayOfWeek.Sunday) 
adjustment = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule(#01/01/1956#, Date.MaxValue.Date, delta, transitionRuleStart, transitionRuleEnd)
adjustmentList.Add(adjustment) 

' Create fictitious time zone   
imaginaryTZ = TimeZoneInfo.CreateCustomTimeZone("Fictitious Standard Time", New TimeSpan(-9, 0, 0), _
                "(GMT-09:00) Fictitious Time", "Fictitious Standard Time", _
                "Fictitious Daylight Time", adjustmentList.ToArray())

注解

此方法创建一个浮动日期规则 (,即在特定月份的特定星期) 的特定星期发生的时间更改。 例如,在 10 月的最后一个星期日发生的时间更改遵循浮动日期规则。

对于从标准时间转换到夏令时,参数 timeOfDay 表示时区标准时间中的转换时间。 对于从夏令时过渡到标准时间,它表示时区夏令时转换的时间。 请注意,这是一个 DateTime 值,其年份、月和日期值必须全部等于 1。

适用于