TimeZoneInfo.AdjustmentRule Class

Provides information about a time zone adjustment, such as the transition to and from daylight saving time.

System.Object
  System.TimeZoneInfo.AdjustmentRule

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

[SerializableAttribute]
[HostProtectionAttribute(SecurityAction.LinkDemand, MayLeakOnAbort = true)]
public sealed class AdjustmentRule : IEquatable<TimeZoneInfo..::..AdjustmentRule>, 
	ISerializable, IDeserializationCallback

The TimeZoneInfo.AdjustmentRule type exposes the following members.

  NameDescription
Public propertyDateEndGets the date when the adjustment rule ceases to be in effect.
Public propertyDateStartGets the date when the adjustment rule takes effect.
Public propertyDaylightDeltaGets the amount of time that is required to form the time zone's daylight saving time. This amount of time is added to the time zone's offset from Coordinated Universal Time (UTC).
Public propertyDaylightTransitionEndGets information about the annual transition from daylight saving time back to standard time.
Public propertyDaylightTransitionStartGets information about the annual transition from standard time to daylight saving time.
Top

  NameDescription
Public methodStatic memberCreateAdjustmentRuleCreates a new adjustment rule for a particular time zone.
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Public methodEquals(TimeZoneInfo.AdjustmentRule)Determines whether the current TimeZoneInfo.AdjustmentRule object is equal to a second TimeZoneInfo.AdjustmentRule object.
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as a hash function for hashing algorithms and data structures such as hash tables. (Overrides Object.GetHashCode().)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

  NameDescription
Explicit interface implemetationPrivate methodIDeserializationCallback.OnDeserializationInfrastructure. Runs when the deserialization of a TimeZoneInfo.AdjustmentRule object is completed.
Explicit interface implemetationPrivate methodISerializable.GetObjectDataInfrastructure. Populates a SerializationInfo object with the data that is required to serialize this object.
Top

The TimeZoneInfo.AdjustmentRule class defines the effective start and end dates of a particular time change to and from daylight saving time, respectively, as well as its delta (the exact amount by which the adjustment causes the time zone's standard time to change). In addition, two properties return TimeZoneInfo.TransitionTime objects that define when each transition to and from standard time occurs.

NoteNote

An instance of the TimeZoneInfo.AdjustmentRule class is immutable. Once an object has been created, its values cannot be modified.

To create a TimeZoneInfo.AdjustmentRule object, call the static (Shared in Visual Basic) TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule method. You can then supply an array of TimeZoneInfo.AdjustmentRule objects to two of the overloads of the TimeZoneInfo.CreateCustomTimeZone method. To retrieve the adjustment rules of a particular time zone, call its TimeZoneInfo.GetAdjustmentRules method, which returns an array of TimeZoneInfo.AdjustmentRule objects.

NoteNote

The HostProtectionAttribute attribute applied to this type or member has the following Resources property value: MayLeakOnAbort. The HostProtectionAttribute does not affect desktop applications (which are typically started by double-clicking an icon, typing a command, or entering a URL in a browser). For more information, see the HostProtectionAttribute class or SQL Server Programming and Host Protection Attributes.

The following example retrieves all time zones defined on the local system and displays complete information about their adjustment rules.


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();
   } 
}


The following is a small portion of the output that is generated by the example. The exact output will vary depending on the operating system and the date on which the example is run.

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

.NET Framework

Supported in: 4, 3.5

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft