TimeZoneInfo.AdjustmentRule Klasse

Definition

Stellt Informationen zu einer Zeitzonenanpassung bereit, z. B. den Übergang zu und von der Sommerzeit.

public: ref class TimeZoneInfo::AdjustmentRule sealed : IEquatable<TimeZoneInfo::AdjustmentRule ^>, System::Runtime::Serialization::IDeserializationCallback, System::Runtime::Serialization::ISerializable
public sealed class TimeZoneInfo.AdjustmentRule : IEquatable<TimeZoneInfo.AdjustmentRule>, System.Runtime.Serialization.IDeserializationCallback, System.Runtime.Serialization.ISerializable
[System.Serializable]
public sealed class TimeZoneInfo.AdjustmentRule : IEquatable<TimeZoneInfo.AdjustmentRule>, System.Runtime.Serialization.IDeserializationCallback, System.Runtime.Serialization.ISerializable
type TimeZoneInfo.AdjustmentRule = class
    interface IEquatable<TimeZoneInfo.AdjustmentRule>
    interface IDeserializationCallback
    interface ISerializable
type TimeZoneInfo.AdjustmentRule = class
    interface IDeserializationCallback
    interface ISerializable
    interface IEquatable<TimeZoneInfo.AdjustmentRule>
[<System.Serializable>]
type TimeZoneInfo.AdjustmentRule = class
    interface IEquatable<TimeZoneInfo.AdjustmentRule>
    interface ISerializable
    interface IDeserializationCallback
Public NotInheritable Class TimeZoneInfo.AdjustmentRule
Implements IDeserializationCallback, IEquatable(Of TimeZoneInfo.AdjustmentRule), ISerializable
Vererbung
TimeZoneInfo.AdjustmentRule
Attribute
Implementiert

Beispiele

Im folgenden Beispiel werden alle zeitzonen abgerufen, die im lokalen System definiert sind, und es werden vollständige Informationen zu ihren Anpassungsregeln angezeigt.

private enum WeekOfMonth 
{
   First = 1,
   Second = 2,
   Third = 3,
   Fourth = 4,
   Last = 5,
}

private static void ShowStartAndEndDates()
{
   // Get all time zones from system
   ReadOnlyCollection<TimeZoneInfo> timeZones = TimeZoneInfo.GetSystemTimeZones();
   string[] monthNames = CultureInfo.CurrentCulture.DateTimeFormat.MonthNames;
   // Get each time zone
   foreach (TimeZoneInfo timeZone in timeZones)
   {
      TimeZoneInfo.AdjustmentRule[] adjustments = timeZone.GetAdjustmentRules();
      // Display message for time zones with no adjustments
      if (adjustments.Length == 0)
      {
         Console.WriteLine("{0} has no adjustment rules", timeZone.StandardName);
      }   
      else
      {
         // Handle time zones with 1 or 2+ adjustments differently
         bool showCount = false;
         int ctr = 0;
         string spacer = "";
         
         Console.WriteLine("{0} Adjustment rules", timeZone.StandardName);
         if (adjustments.Length > 1)
         {
            showCount = true;
            spacer = "   ";
         }   
         // Iterate adjustment rules
         foreach (TimeZoneInfo.AdjustmentRule adjustment in adjustments)
         {
            if (showCount)
            { 
               Console.WriteLine("   Adjustment rule #{0}", ctr+1);
               ctr++;
            }
            // Display general adjustment information
            Console.WriteLine("{0}   Start Date: {1:D}", spacer, adjustment.DateStart);
            Console.WriteLine("{0}   End Date: {1:D}", spacer, adjustment.DateEnd);
            Console.WriteLine("{0}   Time Change: {1}:{2:00} hours", spacer, 
                              adjustment.DaylightDelta.Hours, adjustment.DaylightDelta.Minutes);
            // Get transition start information
            TimeZoneInfo.TransitionTime transitionStart = adjustment.DaylightTransitionStart;
            Console.Write("{0}   Annual Start: ", spacer);
            if (transitionStart.IsFixedDateRule)
            {
               Console.WriteLine("On {0} {1} at {2:t}", 
                                 monthNames[transitionStart.Month - 1], 
                                 transitionStart.Day, 
                                 transitionStart.TimeOfDay);
            }
            else
            {
               Console.WriteLine("The {0} {1} of {2} at {3:t}", 
                                 ((WeekOfMonth)transitionStart.Week).ToString(), 
                                 transitionStart.DayOfWeek.ToString(), 
                                 monthNames[transitionStart.Month - 1], 
                                 transitionStart.TimeOfDay);
            }
            // Get transition end information
            TimeZoneInfo.TransitionTime transitionEnd = adjustment.DaylightTransitionEnd;
            Console.Write("{0}   Annual End: ", spacer);
            if (transitionEnd.IsFixedDateRule)
            {
               Console.WriteLine("On {0} {1} at {2:t}", 
                                 monthNames[transitionEnd.Month - 1], 
                                 transitionEnd.Day, 
                                 transitionEnd.TimeOfDay);
            }
            else
            {
               Console.WriteLine("The {0} {1} of {2} at {3:t}", 
                                 ((WeekOfMonth)transitionEnd.Week).ToString(), 
                                 transitionEnd.DayOfWeek.ToString(), 
                                 monthNames[transitionEnd.Month - 1], 
                                 transitionEnd.TimeOfDay);
            }
         }
      }   
      Console.WriteLine();
   } 
}
type WeekOfMonth = 
    | First = 1
    | Second = 2
    | Third = 3
    | Fourth = 4
    | Last = 5

let showStartAndEndDates () =
    // Get all time zones from system
    let timeZones = TimeZoneInfo.GetSystemTimeZones()
    let monthNames = CultureInfo.CurrentCulture.DateTimeFormat.MonthNames
    // Get each time zone
    for timeZone in timeZones do
        let adjustments = timeZone.GetAdjustmentRules()
        // Display message for time zones with no adjustments
        if adjustments.Length = 0 then
            printfn $"{timeZone.StandardName} has no adjustment rules"
        else
            // Handle time zones with 1 or 2+ adjustments differently
            let mutable ctr = 0
            let showCount, spacer = 
                if adjustments.Length > 1 then
                    true, "   "
                else 
                    false, ""
            printfn $"{timeZone.StandardName} Adjustment rules"

            // Iterate adjustment rules
            for adjustment in adjustments do
                if showCount then
                    printfn $"   Adjustment rule #{ctr + 1}"
                    ctr <- ctr + 1
                // Display general adjustment information
                printfn $"{spacer}   Start Date: {adjustment.DateStart:D}"
                printfn $"{spacer}   End Date: {adjustment.DateEnd:D}"
                printfn $"{spacer}   Time Change: {adjustment.DaylightDelta.Hours}:{adjustment.DaylightDelta.Minutes:D2} hours"
                // Get transition start information
                let transitionStart = adjustment.DaylightTransitionStart
                printf $"{spacer}   Annual Start: "
                if transitionStart.IsFixedDateRule then
                    printfn $"On {monthNames[transitionStart.Month - 1]} {transitionStart.Day} at {transitionStart.TimeOfDay:t}"
                else
                    printfn $"The {transitionStart.Week |> enum<WeekOfMonth>} {transitionStart.DayOfWeek} of {monthNames[transitionStart.Month - 1]} at {transitionStart.TimeOfDay:t}"
                // Get transition end information
                let transitionEnd = adjustment.DaylightTransitionEnd
                printf $"{spacer}   Annual End: "
                if transitionEnd.IsFixedDateRule then
                    printfn $"On {monthNames[transitionEnd.Month - 1]} {transitionEnd.Day} at {transitionEnd.TimeOfDay:t}"
                else
                    printfn $"The {enum<WeekOfMonth> transitionEnd.Week} {transitionEnd.DayOfWeek} of {monthNames[transitionEnd.Month - 1]} at {transitionEnd.TimeOfDay:t}" 
        Console.WriteLine()
Private Enum WeekOfMonth As Integer
   First = 1
   Second = 2
   Third = 3
   Fourth = 4
   Last = 5
End Enum

Private Sub ShowStartAndEndDates()
   ' Get all time zones from system
   Dim timeZones As ReadOnlyCollection(Of TimeZoneInfo) = TimeZoneInfo.GetSystemTimeZones()
   ' Get each time zone
   For Each timeZone As TimeZoneInfo In timeZones
      Dim adjustments() As TimeZoneInfo.AdjustmentRule = timeZone.GetAdjustmentRules()
      ' Display message for time zones with no adjustments
      If adjustments.Length = 0 Then
         Console.WriteLine("{0} has no adjustment rules", timeZone.StandardName)
      Else
         ' Handle time zones with 1 or 2+ adjustments differently
         Dim showCount As Boolean = False
         Dim ctr As Integer = 0
         Dim spacer As String = ""
         
         Console.WriteLine("{0} Adjustment rules", timeZone.StandardName)
         If adjustments.Length > 1 Then showCount = True : spacer = "   "  
         ' Iterate adjustment rules
         For Each adjustment As TimeZoneInfo.AdjustmentRule in adjustments
            If showCount Then 
               Console.WriteLine("   Adjustment rule #{0}", ctr+1)
               ctr += 1
            End If
            ' Display general adjustment information
            Console.WriteLine("{0}   Start Date: {1:D}", spacer, adjustment.DateStart)
            Console.WriteLine("{0}   End Date: {1:D}", spacer, adjustment.DateEnd)
            Console.WriteLine("{0}   Time Change: {1}:{2:00} hours", spacer, _
                              adjustment.DaylightDelta.Hours, adjustment.DaylightDelta.Minutes)
            ' Get transition start information
            Dim transitionStart As TimeZoneInfo.TransitionTime = adjustment.DaylightTransitionStart
            Console.Write("{0}   Annual Start: ", spacer)
            If transitionStart.IsFixedDateRule Then
               Console.WriteLine("On {0} {1} at {2:t}", _
                                 MonthName(transitionStart.Month), _
                                 transitionStart.Day, _
                                 transitionStart.TimeOfDay)
            Else
               Console.WriteLine("The {0} {1} of {2} at {3:t}", _
                                 CType(transitionStart.Week, WeekOfMonth).ToString(), _
                                 transitionStart.DayOfWeek.ToString(), _
                                 MonthName(transitionStart.Month), _
                                 transitionStart.TimeOfDay)
            End If
            ' Get transition end information
            Dim transitionEnd As TimeZoneInfo.TransitionTime = adjustment.DaylightTransitionEnd
                              
            Console.Write("{0}   Annual End: ", spacer)
            If transitionEnd.IsFixedDateRule Then
               Console.WriteLine("On {0} {1} at {2:t}", _
                                 MonthName(transitionEnd.Month), _
                                 transitionEnd.Day, _
                                 transitionEnd.TimeOfDay)
            Else
               Console.WriteLine("The {0} {1} of {2} at {3:t}", _
                                 CType(transitionEnd.Week, WeekOfMonth).ToString(), _
                                 transitionEnd.DayOfWeek.ToString(), _
                                 MonthName(transitionEnd.Month), _
                                 transitionEnd.TimeOfDay)
            End If
         Next
      End If   
      Console.WriteLine()
   Next 
End Sub

Es folgt ein kleiner Teil der Ausgabe, die durch das Beispiel generiert wird. Die genaue Ausgabe variiert je nach Betriebssystem und Datum, an dem das Beispiel ausgeführt wird.

Morocco Standard Time Adjustment rules
   Adjustment rule #1
      Start Date: Tuesday, January 01, 2008
      End Date: Wednesday, December 31, 2008
      Time Change: 1:00 hours
      Annual Start: The Last Saturday of May at 11:59 PM
      Annual End: The Last Sunday of August at 11:59 PM
   Adjustment rule #2
      Start Date: Thursday, January 01, 2009
      End Date: Thursday, December 31, 2009
      Time Change: 1:00 hours
      Annual Start: The Last Sunday of May at 11:59 PM
      Annual End: The Third Thursday of August at 11:59 PM

Coordinated Universal Time has no adjustment rules

GMT Standard Time Adjustment rules
   Start Date: Monday, January 01, 0001
   End Date: Friday, December 31, 9999
   Time Change: 1:00 hours
   Annual Start: The Last Sunday of March at 1:00 AM
   Annual End: The Last Sunday of October at 2:00 AM

Greenwich Standard Time has no adjustment rules

W. Europe Standard Time Adjustment rules
   Start Date: Monday, January 01, 0001
   End Date: Friday, December 31, 9999
   Time Change: 1:00 hours
   Annual Start: The Last Sunday of March at 2:00 AM
   Annual End: The Last Sunday of October at 3:00 AM

Central Europe Standard Time Adjustment rules
   Start Date: Monday, January 01, 0001
   End Date: Friday, December 31, 9999
   Time Change: 1:00 hours
   Annual Start: The Last Sunday of March at 2:00 AM
   Annual End: The Last Sunday of October at 3:00 AM

Romance Standard Time Adjustment rules
   Start Date: Monday, January 01, 0001
   End Date: Friday, December 31, 9999
   Time Change: 1:00 hours
   Annual Start: The Last Sunday of March at 2:00 AM
   Annual End: The Last Sunday of October at 3:00 AM

Central European Standard Time Adjustment rules
   Start Date: Monday, January 01, 0001
   End Date: Friday, December 31, 9999
   Time Change: 1:00 hours
   Annual Start: The Last Sunday of March at 2:00 AM
   Annual End: The Last Sunday of October at 3:00 AM

W. Central Africa Standard Time has no adjustment rules

Hinweise

Die TimeZoneInfo.AdjustmentRule Klasse definiert die effektiven Anfangs- und Enddaten einer bestimmten Zeitänderung bzw. von Sommerzeit sowie delta (der genaue Betrag, um den die Anpassung bewirkt, dass sich die Standardzeit der Zeitzone ändert). Darüber hinaus geben zwei Eigenschaften Objekte zurück TimeZoneInfo.TransitionTime , die definieren, wann jeder Übergang zu und von der Standardzeit erfolgt.

Note

Eine Instanz der TimeZoneInfo.AdjustmentRule Klasse ist unveränderlich. Nachdem ein Objekt erstellt wurde, können seine Werte nicht mehr geändert werden.

Rufen Sie zum Erstellen eines TimeZoneInfo.AdjustmentRule-Objekts die static (Shared in Visual Basic) TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule-Methode auf. Anschließend können Sie ein Array von TimeZoneInfo.AdjustmentRule Objekten an zwei der Überladungen der TimeZoneInfo.CreateCustomTimeZone Methode angeben. Rufen Sie die Methode auf TimeZoneInfo.GetAdjustmentRules , die ein Array von TimeZoneInfo.AdjustmentRule Objekten zurückgibt, um die Anpassungsregeln einer bestimmten Zeitzone abzurufen.

Eigenschaften

Name Beschreibung
BaseUtcOffsetDelta

Ruft die Zeitdifferenz mit dem UTC-Basisoffset für die Zeitzone während des Anpassungsregelzeitraums ab.

DateEnd

Ruft das Datum ab, an dem die Anpassungsregel nicht mehr wirksam ist.

DateStart

Ruft das Datum ab, an dem die Anpassungsregel wirksam wird.

DaylightDelta

Ruft den Zeitraum ab, der zum Bilden der Sommerzeit der Zeitzone erforderlich ist. Diese Zeitspanne wird dem Offset der Zeitzone aus koordinierter Weltzeit (COORDINATED Universal Time, UTC) hinzugefügt.

DaylightTransitionEnd

Ruft Informationen zum jährlichen Übergang von Sommerzeit zurück zur Standardzeit ab.

DaylightTransitionStart

Ruft Informationen zum jährlichen Übergang von Standardzeit zu Sommerzeit ab.

Methoden

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

Erstellt eine neue Anpassungsregel für eine bestimmte Zeitzone.

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

Erstellt eine neue Anpassungsregel für eine bestimmte Zeitzone.

Equals(Object)

Gibt an, ob die aktuelle Instanz einer anderen Instanz entspricht.

Equals(Object)

Bestimmt, ob das angegebene Objekt dem aktuellen Objekt entspricht.

(Geerbt von Object)
Equals(TimeZoneInfo+AdjustmentRule)

Bestimmt, ob das aktuelle TimeZoneInfo.AdjustmentRule Objekt einem zweiten TimeZoneInfo.AdjustmentRule Objekt entspricht.

GetHashCode()

Dient als Hashfunktion für Hashingalgorithmen und Datenstrukturen wie Hashtabellen.

GetType()

Ruft die Type der aktuellen Instanz ab.

(Geerbt von Object)
MemberwiseClone()

Erstellt eine flache Kopie der aktuellen Object.

(Geerbt von Object)
ToString()

Gibt eine Zeichenfolge zurück, die das aktuelle Objekt darstellt.

(Geerbt von Object)

Explizite Schnittstellenimplementierungen

Name Beschreibung
IDeserializationCallback.OnDeserialization(Object)

Wird ausgeführt, wenn die Deserialisierung eines TimeZoneInfo.AdjustmentRule Objekts abgeschlossen ist.

ISerializable.GetObjectData(SerializationInfo, StreamingContext)

Füllt ein SerializationInfo Objekt mit den Daten auf, die zum Serialisieren dieses Objekts erforderlich sind.

Gilt für:

Weitere Informationen