共用方式為


TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule 方法

定義

多載

CreateAdjustmentRule(DateTime, DateTime, TimeSpan, TimeZoneInfo+TransitionTime, TimeZoneInfo+TransitionTime)

為特定時區建立新的調整規則。

CreateAdjustmentRule(DateTime, DateTime, TimeSpan, TimeZoneInfo+TransitionTime, TimeZoneInfo+TransitionTime, TimeSpan)

為特定時區建立新的調整規則。

CreateAdjustmentRule(DateTime, DateTime, TimeSpan, TimeZoneInfo+TransitionTime, TimeZoneInfo+TransitionTime)

來源:
TimeZoneInfo.AdjustmentRule.cs
來源:
TimeZoneInfo.AdjustmentRule.cs
來源:
TimeZoneInfo.AdjustmentRule.cs

為特定時區建立新的調整規則。

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

調整規則的生效日期。 如果 dateStart 參數的值是 DateTime.MinValue.Date,這會是第一個生效的時區調整規則。

dateEnd
DateTime

調整規則有效的最後一個日期。 如果 dateEnd 參數的值是 DateTime.MaxValue.Date,則調整規則沒有結束日期。

daylightDelta
TimeSpan

調整所導致的時間變更。 這個值會加入時區的 BaseUtcOffset 屬性中,以取得與國際標準時間 (UTC) 的正確日光節約位移。 這個值的範圍可從 -14 到 14。

daylightTransitionStart
TimeZoneInfo.TransitionTime

定義日光節約時間起始的物件。

daylightTransitionEnd
TimeZoneInfo.TransitionTime

定義日光節約時間結束的物件。

傳回

表示新調整規則的物件。

例外狀況

dateStartdateEnd 參數的 Kind 屬性不等於 Unspecified

-或-

daylightTransitionStart 參數等於 daylightTransitionEnd 參數。

-或-

dateStartdateEnd 參數包含日期時間值。

dateEnd 早於 dateStart

-或-

daylightDelta 小於 -14 或大於 14。

-或-

daylightDelta 參數的 Milliseconds 屬性不等於 0。

-或-

daylightDelta 參數的 Ticks 屬性不等於整數秒數。

範例

下列範例會建立替代的中央標準時區,並定義 1976-1986、1987-2006 和 2007 和更新版本三個調整規則。 這些規則會新增至泛型 List<T> 物件,其專案接著會 TimeZoneInfo.AdjustmentRule 複製到陣列。 接著,這個陣列會用於方法的 TimeZoneInfo.CreateCustomTimeZone(String, TimeSpan, String, String, String, TimeZoneInfo+AdjustmentRule[]) 呼叫中。

// 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
let delta = TimeSpan(1, 0, 0)
let adjustmentList = ResizeArray()

// Define end rule (for 1976-2006)
let transitionRuleEnd = TimeZoneInfo.TransitionTime.CreateFloatingDateRule(DateTime(1, 1, 1, 2, 0, 0), 10, 5, DayOfWeek.Sunday)
// Define rule (1976-1986)
let transitionRuleStart = TimeZoneInfo.TransitionTime.CreateFloatingDateRule(DateTime(1, 1, 1, 2, 0, 0), 04, 05, DayOfWeek.Sunday)
TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule(DateTime(1976, 1, 1), DateTime(1986, 12, 31), delta, transitionRuleStart, transitionRuleEnd)
|> adjustmentList.Add
// Define rule (1987-2006)  
let transitionRuleStart = TimeZoneInfo.TransitionTime.CreateFloatingDateRule(DateTime(1, 1, 1, 2, 0, 0), 04, 01, DayOfWeek.Sunday)
TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule(DateTime(1987, 1, 1), DateTime(2006, 12, 31), delta, transitionRuleStart, transitionRuleEnd)
|> adjustmentList.Add
// Define rule (2007- )  
let transitionRuleStart = TimeZoneInfo.TransitionTime.CreateFloatingDateRule(DateTime(1, 1, 1, 2, 0, 0), 03, 02, DayOfWeek.Sunday)
let transitionRuleEnd = TimeZoneInfo.TransitionTime.CreateFloatingDateRule(DateTime(1, 1, 1, 2, 0, 0), 11, 01, DayOfWeek.Sunday)
TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule(DateTime(2007, 01, 01), DateTime.MaxValue.Date, delta, transitionRuleStart, transitionRuleEnd)
|> adjustmentList.Add
            
// Create custom U.S. Central Standard Time zone         
TimeZoneInfo.CreateCustomTimeZone("Central Standard Time", 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())

備註

您可以使用這個方法來建立自訂時區的一或多個調整規則。 接著,呼叫這個方法所傳回之 物件的陣列 TimeZoneInfo.AdjustmentRule 可以當做 adjustmentRules 參數傳遞至方法的兩個 CreateCustomTimeZone 多載。 此範例說明此程式。

注意

方法 CreateAdjustmentRule 只能用來定義新時區的調整規則;它不能用來修改現有時區的調整規則。

dateStartdateEnd 參數必須是沒有時間元件的日期值,否則 ArgumentException 會擲回 。 從日期和時間的 Date 屬性擷取 DateTime 值,即可移除時間元件,如下列語句所示:

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

KinddateEnd 參數的 dateStart 屬性也必須是 DateTimeKind.Unspecified

參數的值 daylightDelta 可以介於 -14 到 14 之間。 方法呼叫 TimeZoneInfo.CreateCustomTimeZone 中使用的參數和參數的總 daylightDeltabaseUtcOffset 也必須從 -14 到 14 範圍,否則 InvalidTimeZoneException 會擲回 。

注意

參數 daylightDelta 會定義時區的標準時間與其日光節約時間之間的差異。 它並非用來定義時區的標準時間位移,從國際標準時間 (UTC) 。 類別 TimeZoneInfo 假設這個與 UTC 的位移在時區的生命週期中都是固定的。 若要反映時區與 UTC 位移的變更,不是因為調整規則的套用所造成,您必須使用 CreateCustomTimeZone 方法來建立新的自訂時區。

適用於

CreateAdjustmentRule(DateTime, DateTime, TimeSpan, TimeZoneInfo+TransitionTime, TimeZoneInfo+TransitionTime, TimeSpan)

來源:
TimeZoneInfo.AdjustmentRule.cs
來源:
TimeZoneInfo.AdjustmentRule.cs
來源:
TimeZoneInfo.AdjustmentRule.cs

為特定時區建立新的調整規則。

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

參數

dateStart
DateTime

調整規則的生效日期。 如果值為 DateTime.MinValue.Date ,這是時區生效的第一個調整規則。

dateEnd
DateTime

調整規則有效的最後一個日期。 如果值為 DateTime.MaxValue.Date ,則調整規則沒有結束日期。

daylightDelta
TimeSpan

調整所導致的時間變更。 此值會新增至時區 BaseUtcOffset 的 和 BaseUtcOffsetDelta 屬性,以從國際標準時間 (UTC) 取得正確的日光節約位移。 這個值的範圍可從 -14 到 14。

daylightTransitionStart
TimeZoneInfo.TransitionTime

日光節約時間的開始。

daylightTransitionEnd
TimeZoneInfo.TransitionTime

日光節約時間結束。

baseUtcOffsetDelta
TimeSpan

在調整規則期間,時區的基底 UTC 位移時間差異。

傳回

新的調整規則。

適用於