Export (0) Print
Expand All

TimeZoneInfo.TransitionTime.TimeOfDay Property

Gets the hour, minute, and second at which the time change occurs.

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

public DateTime TimeOfDay { get; }

Property Value

Type: System.DateTime
The time of day at which the time change occurs.

For transitions from standard time to daylight saving time, the TimeOfDay value represents the time of the transition in the time zone's standard time. For transitions from daylight saving time to standard time, it represents the time of the transition in the time zone's daylight saving time.

The TimeOfDay property defines only the time of a time change, but not its date. The date is determined by the Month and Day properties for fixed-rule changes, and by the Month, Week, and DayOfWeek properties for floating-rule changes. The date component of this DateTime value is ignored; the value of the year, month, and day is always 1.

The TimeOfDay property is used for both fixed-date and floating-date transitions.

The following example enumerates the time zones found on the local computer and displays transition time information for those time zones that have adjustment rules. The time information includes the time of day at which the time change occurs.

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

public void GetAllTransitionTimes()
{
   ReadOnlyCollection<TimeZoneInfo> timeZones = TimeZoneInfo.GetSystemTimeZones();
   DateTimeFormatInfo dateInfo = CultureInfo.CurrentCulture.DateTimeFormat;

   foreach (TimeZoneInfo zone in timeZones)
   {
      Console.WriteLine("{0} transition time information:", zone.StandardName);
      TimeZoneInfo.AdjustmentRule[] adjustmentRules= zone.GetAdjustmentRules();

      // Indicate that time zone has no adjustment rules 
      if (adjustmentRules.Length == 0)
      { 
         Console.WriteLine("   No adjustment rules defined.");
      }   
      else
      {
         // Iterate adjustment rules        
         foreach (TimeZoneInfo.AdjustmentRule adjustmentRule in adjustmentRules)
         {
            Console.WriteLine("   Adjustment rule from {0:d} to {1:d}:", 
                              adjustmentRule.DateStart, 
                              adjustmentRule.DateEnd);                                 

            // Get start of transition
            TimeZoneInfo.TransitionTime daylightStart = adjustmentRule.DaylightTransitionStart;
            // Display information on fixed date rule 
            if (! daylightStart.IsFixedDateRule)
               Console.WriteLine("      Begins at {0:t} on the {1} {2} of {3}.", 
                              daylightStart.TimeOfDay, 
                              ((WeekOfMonth)daylightStart.Week).ToString(),  
                              daylightStart.DayOfWeek.ToString(), 
                              dateInfo.GetMonthName(daylightStart.Month));
            // Display information on floating date rule  
            else
               Console.WriteLine("      Begins at {0:t} on the {1} {2} of {3}.", 
                                 daylightStart.TimeOfDay, 
                                 ((WeekOfMonth)daylightStart.Week).ToString(),  
                                 daylightStart.DayOfWeek.ToString(), 
                                 dateInfo.GetMonthName(daylightStart.Month));

            // Get end of transition
            TimeZoneInfo.TransitionTime daylightEnd = adjustmentRule.DaylightTransitionEnd;
            // Display information on fixed date rule 
            if (! daylightEnd.IsFixedDateRule)
               Console.WriteLine("      Ends at {0:t} on the {1} {2} of {3}.", 
                              daylightEnd.TimeOfDay, 
                              ((WeekOfMonth)daylightEnd.Week).ToString(),  
                              daylightEnd.DayOfWeek.ToString(), 
                              dateInfo.GetMonthName(daylightEnd.Month));
            // Display information on floating date rule 
            else
               Console.WriteLine("      Ends at {0:t} on the {1} {2} of {3}.", 
                                 daylightStart.TimeOfDay, 
                                 ((WeekOfMonth)daylightStart.Week).ToString(),  
                                 daylightStart.DayOfWeek.ToString(), 
                                 dateInfo.GetMonthName(daylightStart.Month));
         }
      }   
   }   
}   

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Show:
© 2015 Microsoft