Display the current date and time and show if they occur in daylight saving time.
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;
Console.WriteLine( "\n" + timeFmt, "Current date and time:",currentDate );
Console.WriteLine( dataFmt, "Daylight saving time?", localZone.IsDaylightSavingTime( currentDate ) );
}
}
Related examples in the same category