TimeZoneInfo.AdjustmentRule.DateEnd Propiedad
Definición
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
Obtiene la fecha en la que la regla de ajuste deja de estar en vigor.
public:
property DateTime DateEnd { DateTime get(); };
public DateTime DateEnd { get; }
member this.DateEnd : DateTime
Public ReadOnly Property DateEnd As DateTime
Valor de propiedad
Valor DateTime que indica la fecha de finalización de la regla de ajuste.
Ejemplos
En el ejemplo siguiente se muestra información sobre todas las zonas horarias definidas en el registro del sistema del equipo local, incluidas las fechas de inicio y finalización de sus reglas de ajuste.
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.
Comentarios
El valor de la DateEnd propiedad es un valor de fecha sin un componente de hora.
Dado que normalmente no se conoce la fecha de finalización de la regla de ajuste actual, puede asignarla DateTime.MaxValue.Date
a la DateEnd propiedad al crear una regla de ajuste personalizada.
Importante
A menos que haya una razón atractiva para hacerlo de otro modo, debe definir la fecha de finalización de la regla de ajuste para que se produzca dentro del intervalo de tiempo durante el que la zona horaria observe la hora estándar. A menos que haya una razón atractiva para hacerlo, no debe definir la fecha de finalización de la regla de ajuste para que se produzca dentro del intervalo de tiempo durante el cual la zona horaria observe el horario de verano. Por ejemplo, si la transición de una zona horaria desde el horario de verano se produce el tercer domingo de marzo y su transición al horario de verano se produce el primer domingo de octubre, la fecha de finalización efectiva de la regla de ajuste no debe ser el 31 de diciembre de un año determinado, ya que esa fecha se produce dentro del período de horario de verano.
De forma predeterminada, el Registro de Windows XP define una única regla de ajuste cuya fecha de finalización es el viernes 31 de diciembre de 9999 (el valor de DateTime.MaxValue.Date
), para cada zona horaria. En el caso de las zonas horarias de la Estados Unidos, el registro de Windows Vista define dos reglas de ajuste:
Lunes, 01 de enero de 0001, al domingo 31 de diciembre de 2006.
Lunes, 1 de enero de 2007, hasta el viernes 31 de diciembre de 9999.
Esto significa que, aunque las reglas de ajuste de zona horaria almacenadas en el registro son útiles para realizar operaciones relacionadas con la zona horaria actual, no se pueden usar de forma confiable para recuperar información histórica de zona horaria. Para obtener información sobre cómo definir una zona horaria personalizada con varias reglas de ajuste que se pueden usar en una aplicación histórica con reconocimiento de zona horaria, consulte How to: Create Time Zones with Adjustment Rules.