TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule(DateTime, DateTime, TimeSpan, TimeZoneInfo+TransitionTime, TimeZoneInfo+TransitionTime) TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule(DateTime, DateTime, TimeSpan, TimeZoneInfo+TransitionTime, TimeZoneInfo+TransitionTime) TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule(DateTime, DateTime, TimeSpan, TimeZoneInfo+TransitionTime, TimeZoneInfo+TransitionTime) TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule(DateTime, DateTime, TimeSpan, TimeZoneInfo+TransitionTime, TimeZoneInfo+TransitionTime) Method

Definizione

Crea una nuova regola di rettifica per un fuso orario specifico.Creates a new adjustment rule for a particular time zone.

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

Parametri

dateStart
DateTime DateTime DateTime DateTime

Data di validità della regola di rettifica.The effective date of the adjustment rule. Se il valore del parametro dateStart è DateTime.MinValue.Date, questa è la prima regola di rettifica valida per un fuso orario.If the value of the dateStart parameter is DateTime.MinValue.Date, this is the first adjustment rule in effect for a time zone.

dateEnd
DateTime DateTime DateTime DateTime

Ultima data di validità della regola di rettifica.The last date that the adjustment rule is in force. Se il valore del parametro dateEnd è DateTime.MaxValue.Date, la regola di rettifica non ha una data di fine.If the value of the dateEnd parameter is DateTime.MaxValue.Date, the adjustment rule has no end date.

daylightDelta
TimeSpan TimeSpan TimeSpan TimeSpan

Cambiamento di ora risultante dalla rettifica.The time change that results from the adjustment. Questo valore viene aggiunto alla proprietà BaseUtcOffset del fuso orario per ottenere l'offset corretto dell'ora legale rispetto al fuso orario UTC (Coordinated Universal Time).This value is added to the time zone's BaseUtcOffset property to obtain the correct daylight offset from Coordinated Universal Time (UTC). Questo valore può andare da -14 a 14.This value can range from -14 to 14.

daylightTransitionStart
TimeZoneInfo.TransitionTime TimeZoneInfo.TransitionTime TimeZoneInfo.TransitionTime TimeZoneInfo.TransitionTime

Oggetto che definisce l'inizio dell'ora legale.An object that defines the start of daylight saving time.

daylightTransitionEnd
TimeZoneInfo.TransitionTime TimeZoneInfo.TransitionTime TimeZoneInfo.TransitionTime TimeZoneInfo.TransitionTime

Oggetto che definisce la fine dell'ora legale.An object that defines the end of daylight saving time.

Restituisce

Oggetto che rappresenta la nuova regola di rettifica.An object that represents the new adjustment rule.

Eccezioni

La proprietà Kind del parametro dateStart o dateEnd non è uguale a Unspecified.The Kind property of the dateStart or dateEnd parameter does not equal Unspecified.

-oppure--or- Il parametro daylightTransitionStart è uguale al parametro daylightTransitionEnd.The daylightTransitionStart parameter is equal to the daylightTransitionEnd parameter.

In alternativa-or- Il parametro dateStart o dateEnd include un valore relativo a un'ora del giorno.The dateStart or dateEnd parameter includes a time of day value.

dateEnd è precedente a dateStart.dateEnd is earlier than dateStart.

In alternativa-or- daylightDelta è minore di -14 o maggiore di 14.daylightDelta is less than -14 or greater than 14.

-oppure--or- La proprietà Milliseconds del parametro daylightDelta non è uguale a 0.The Milliseconds property of the daylightDelta parameter is not equal to 0.

-oppure--or- La proprietà Ticks del parametro daylightDelta non è uguale a un numero intero di secondi.The Ticks property of the daylightDelta parameter does not equal a whole number of seconds.

Esempi

Nell'esempio seguente viene creato un fuso orario standard centrale alternativo e vengono definite tre regole di rettifica per i periodi 1976-1986, 1987-2006 e 2007 e oltre.The following example creates an alternate Central Standard Time zone and defines three adjustment rules for the periods 1976-1986, 1987-2006, and 2007 and beyond. Queste regole vengono aggiunte a un oggetto List<T> generico i cui elementi vengono quindi copiati TimeZoneInfo.AdjustmentRule in una matrice.These rules are added to a generic List<T> object whose elements are then copied to a TimeZoneInfo.AdjustmentRule array. Questa matrice viene quindi utilizzata nella chiamata al TimeZoneInfo.CreateCustomTimeZone(String, TimeSpan, String, String, String, TimeZoneInfo+AdjustmentRule[]) metodo.This array is then used in the call to the TimeZoneInfo.CreateCustomTimeZone(String, TimeSpan, String, String, String, TimeZoneInfo+AdjustmentRule[]) method.

// 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
'
' 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())     

Commenti

È possibile utilizzare questo metodo per creare una o più regole di rettifica per un fuso orario personalizzato.You can use this method to create one or more adjustment rules for a custom time zone. Una matrice degli TimeZoneInfo.AdjustmentRule oggetti restituiti dalle chiamate a questo metodo può quindi essere passata adjustmentRules come parametro a due overload del CreateCustomTimeZone metodo.An array of the TimeZoneInfo.AdjustmentRule objects returned by calls to this method can then be passed as the adjustmentRules parameter to two overloads of the CreateCustomTimeZone method. Nell'esempio viene illustrata questa procedura.The example illustrates this procedure.

Nota

Il CreateAdjustmentRule metodo può essere usato solo per definire una regola di rettifica per un nuovo fuso orario. non può essere usato per modificare una regola di rettifica per un fuso orario esistente.The CreateAdjustmentRule method can be used only to define an adjustment rule for a new time zone; it cannot be used to modify an adjustment rule for an existing time zone.

I dateStart parametri dateEnd e devono essere valori di data senza un componente ora oppure ArgumentException viene generata un'eccezione.The dateStart and dateEnd parameters must be date values without a time component or an ArgumentException is thrown. Il componente ora può essere rimosso recuperando un DateTime valore dalla Date proprietà data e ora, come illustrato nelle istruzioni seguenti:The time component can be removed by retrieving a DateTime value from the date and time's Date property as shown in the following statements:

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

Anche Kind la proprietà dateStart dei parametri dateEnd e deve essere DateTimeKind.Unspecified.The Kind property of the dateStart and dateEnd parameters must also be DateTimeKind.Unspecified.

Il valore del daylightDelta parametro può essere compreso tra-14 e 14.The value of the daylightDelta parameter can range from -14 to 14. La somma del daylightDelta parametro e del baseUtcOffset parametro usato TimeZoneInfo.CreateCustomTimeZone nella chiamata al metodo deve essere compresa tra-14 e 14 o viene generata un' InvalidTimeZoneException eccezione.The sum of the daylightDelta parameter and the baseUtcOffset parameter used in the call to the TimeZoneInfo.CreateCustomTimeZone method must also range from -14 to 14 or an InvalidTimeZoneException is thrown.

Nota

Il daylightDelta parametro definisce la differenza tra l'ora solare e l'ora legale del fuso orario.The daylightDelta parameter defines the difference between a time zone's standard time and its daylight saving time. Non è progettato per definire l'offset dell'ora solare del fuso orario rispetto all'ora UTC (Coordinated Universal Time).It is not intended to define the time zone's standard time offset from Coordinated Universal Time (UTC). La TimeZoneInfo classe presuppone che questo offset dall'ora UTC sia costante per tutta la durata del fuso orario.The TimeZoneInfo class assumes that this offset from UTC is constant throughout the life of the time zone. Per riflettere una modifica nell'offset di un fuso orario rispetto all'ora UTC non causata dall'applicazione di una regola di rettifica, è necessario utilizzare il CreateCustomTimeZone metodo per creare un nuovo fuso orario personalizzato.To reflect a change in a time zone's offset from UTC that is not caused by the application of an adjustment rule, you must use the CreateCustomTimeZone method to create a new custom time zone.

Si applica a