共用方式為


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 屬性。

傳回

時間變更的相關資料。

例外狀況

timeOfDay 參數具有非預設的日期元件。

-或-

timeOfDay 參數不表示整數毫秒數。

-或-

timeOfDay 參數的 Kind 屬性不是 Unspecified

month 小於 1 或大於 12。

-或-

week 小於 1 或大於 5。

-或-

dayOfWeek 參數不是 DayOfWeek 列舉的成員。

範例

下列範例會使用固定日期規則和浮點數規則,為虛時區建立時區轉換。 浮點數規則會定義時區調整,從 3 月的最後一個星期日的上午 2:00 開始,並在 1956 年之後的第四個星期日結束于上午 3:00。

// 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 的值。

適用於