TimeZoneInfo.AdjustmentRule.DateEnd 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得調整規則停止生效的日期。
public:
property DateTime DateEnd { DateTime get(); };
public DateTime DateEnd { get; }
member this.DateEnd : DateTime
Public ReadOnly Property DateEnd As DateTime
屬性值
DateTime 值,表示調整規則的結束日期。
範例
下列範例會顯示本機電腦系統登錄中定義之所有時區的相關資訊,包括調整規則的開始和結束日期。
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.
open System
open System.Globalization
let timeZones = TimeZoneInfo.GetSystemTimeZones()
let dateInfo = CultureInfo.CurrentCulture.DateTimeFormat
type WeekOfMonth =
| First = 1
| Second = 2
| Third = 3
| Fourth = 4
| Last = 5
for zone in timeZones do
printfn $"{zone.StandardName} transition time information:"
printfn " Time zone information: "
printfn $" Base UTC Offset: {zone.BaseUtcOffset}"
printfn $" Supports DST: {zone.SupportsDaylightSavingTime}"
let adjustmentRules= zone.GetAdjustmentRules()
// Indicate that time zone has no adjustment rules
if adjustmentRules.Length = 0 then
printfn " No adjustment rules defined."
else
printfn $" Adjustment Rules: {adjustmentRules.Length}"
// Iterate adjustment rules
for adjustmentRule in adjustmentRules do
printfn $" Adjustment rule from {adjustmentRule.DateStart:d} to {adjustmentRule.DateEnd:d}:"
printfn $" Delta: {adjustmentRule.DaylightDelta}"
// Get start of transition
let daylightStart = adjustmentRule.DaylightTransitionStart
// Display information on floating date rule
if not daylightStart.IsFixedDateRule then
printfn $" Begins at {daylightStart.TimeOfDay:t} on the {enum<WeekOfMonth> daylightStart.Week} {daylightStart.DayOfWeek} of {dateInfo.GetMonthName daylightStart.Month}"
// Display information on fixed date rule
else
printfn $" Begins at {daylightStart.TimeOfDay:t} on {dateInfo.GetMonthName daylightStart.Month} {daylightStart.Day}"
// Get end of transition.
let daylightEnd = adjustmentRule.DaylightTransitionEnd
// Display information on floating date rule.
if not daylightEnd.IsFixedDateRule then
printfn $" Ends at {daylightEnd.TimeOfDay:t} on the {enum<WeekOfMonth> daylightEnd.Week} {daylightEnd.DayOfWeek} of {dateInfo.GetMonthName daylightEnd.Month}"
// Display information on fixed date rule.
else
printfn $" Ends at {daylightEnd.TimeOfDay:t} on {dateInfo.GetMonthName daylightEnd.Month} {daylightEnd.Day}"
// 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.
備註
屬性的值 DateEnd 是沒有時間元件的日期值。
由於目前調整規則的結束日期通常未知,因此您可以在建立自訂調整規則時指派 DateTime.MaxValue.Date
給 DateEnd 屬性。
重要
除非有令人信服的原因,否則您應該定義調整規則的結束日期,以在時區觀察標準時間的時間間隔內發生。 除非有吸引人的理由這樣做,否則您不應該定義調整規則的結束日期,以在時區觀察日光節約時間的時間間隔內發生。 例如,如果時區從日光節約時間的轉換發生在三月的第三個星期日,而其轉換到日光節約時間發生在 10 月的第一個星期日,則調整規則的有效結束日期不應該是特定年份的 12 月 31 日,因為該日期會在日光節約時間期間內發生。
根據預設,Windows XP 中的登錄會定義單一調整規則,其結束日期是 9999 年 12 月 31 日星期五,9999 年 12 月 31 日 (每個時區的 DateTime.MaxValue.Date
) 值。 針對美國中的時區,Windows Vista 中的登錄會定義兩個調整規則:
Monday,January 01, 0001, to Sunday, December 31, 2006.
2007 年 1 月 1 日星期一、2007 年 12 月 31 日到星期五,9999 年 12 月 31 日。
這表示,雖然儲存在登錄中的時區調整規則對於執行目前的時區相關作業很有用,但它們無法可靠地用於擷取歷程記錄時區資訊。 如需使用多個調整規則定義自訂時區的相關資訊,這些規則可用於歷史時區感知應用程式中,請參閱 如何:建立具有調整規則的時區。