TimeZoneInfo.GetAdjustmentRules() : TimeZoneInfo « System.Globalization « C# / C Sharp by API






TimeZoneInfo.GetAdjustmentRules()

  


using System;
using System.Globalization;
public class MainClass {
    public static void Main() {
        TimeZoneInfo wa = TimeZoneInfo.FindSystemTimeZoneById("W. Australia Standard Time");

        foreach (TimeZoneInfo.AdjustmentRule rule in wa.GetAdjustmentRules()) {
            Console.WriteLine("Rule: applies from " + rule.DateStart +
                                              " to " + rule.DateEnd);

            Console.WriteLine("   Delta: " + rule.DaylightDelta);

            Console.WriteLine("   Start: " + FormatTransitionTime
                                             (rule.DaylightTransitionStart, false));

            Console.WriteLine("   End:   " + FormatTransitionTime
                                             (rule.DaylightTransitionEnd, true));
            Console.WriteLine();
        }
    }
    static string FormatTransitionTime(TimeZoneInfo.TransitionTime tt,
                                    bool endTime) {
        if (endTime && tt.IsFixedDateRule
                    && tt.Day == 1 && tt.Month == 1
                    && tt.TimeOfDay == DateTime.MinValue)
            return "-";

        string s;
        if (tt.IsFixedDateRule)
            s = tt.Day.ToString();
        else
            s = "The first second third fourth last".Split()[tt.Week - 1] +
                " " + tt.DayOfWeek + " in";

        return s + " " + DateTimeFormatInfo.CurrentInfo.MonthNames[tt.Month - 1]
                 + " at " + tt.TimeOfDay.TimeOfDay;
    }
}

   
    
  








Related examples in the same category

1.TimeZoneInfo.AdjustmentRule
2.TimeZoneInfo.BaseUtcOffset
3.TimeZoneInfo.DisplayName
4.TimeZoneInfo.FindSystemTimeZoneById
5.TimeZoneInfo.GetSystemTimeZones()
6.TimeZoneInfo.Local
7.TimeZoneInfo.SupportsDaylightSavingTime