Advertise with us

TimeZone class in C#

Can anyone provide me an example of TimeZone class?
Last updated:6/12/2013 7:13:40 AM

1 Answers

Vijay Shukla
Vijay Shukla

Hey Ankit Singh!
I will provide you some line of code below:-


class TimeZoneDemo
{
    static void Main()
    {
        Console.WriteLine("{0,-30}{1}", "Standard time name:",
        TimeZone.CurrentTimeZone.StandardName);
        Console.WriteLine("{0,-30}{1}", "Daylight saving time name:",
        TimeZone.CurrentTimeZone.DaylightName);
        Console.WriteLine("\n" + "{0,-30}{1:MM-dd-yyyy HH:mm}", "Current date and time:",
        DateTime.Now);
        Console.WriteLine("{0,-30}{1}", "Daylight saving time?",
        TimeZone.CurrentTimeZone.IsDaylightSavingTime(DateTime.Now));
        DateTime currentUTC = TimeZone.CurrentTimeZone.ToUniversalTime(DateTime.Now);
        TimeSpan currentOffset = TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now);
        Console.WriteLine("{0,-30}{1:MM-dd-yyyy HH:mm}", "Coordinated Universal Time:",
        currentUTC);
        Console.WriteLine("{0,-30}{1}", "UTC offset:", currentOffset);
        DaylightTime daylight =
        TimeZone.CurrentTimeZone.GetDaylightChanges(DateTime.Now.Year);
        Console.WriteLine("\nDaylight saving time for year {0}:", DateTime.Now.Year);
        Console.WriteLine("{0:MM-dd-yyyy HH:mm} to " + "{1:MM-dd-yyyy HH:mm}, delta: {2}",
        daylight.Start, daylight.End, daylight.Delta);
        Console.ReadKey();
    }
}
And if you want to more knowledge about the TimeZone Class read this article

Last updated:6/12/2013 7:13:40 AM

Answer