Mega Code Archive

 
Categories / C# / Date Time
 

Display the daylight saving time range for the current year

using System; using System.Globalization; class TimeZoneDemo {     static void Main( )     {         const string dataFmt = "{0,-30}{1}";         const string timeFmt = "{0,-30}{1:yyyy-MM-dd HH:mm}";         TimeZone localZone = TimeZone.CurrentTimeZone;         DateTime currentDate = DateTime.Now;         int      currentYear = currentDate.Year;         DaylightTime daylight = localZone.GetDaylightChanges( currentYear );         Console.WriteLine( "Daylight saving time for year {0}:", currentYear );         Console.WriteLine( "{0:yyyy-MM-dd HH:mm} to " +"{1:yyyy-MM-dd HH:mm}, delta: {2}", daylight.Start, daylight.End, daylight.Delta );     } }