Home > DeveloperSection > Forums > TimeZone class in C#
Ankit Singh

Total Post:341

Points:2389
Posted on    June-12-2013 7:00 AM

 C# C# 
Ratings:


 1 Reply(s)
 800  View(s)
Rate this:
Can anyone provide me an example of TimeZone class?


Vijay Shukla

Total Post:100

Points:700
Posted on    June-12-2013 7:13 AM

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

Modified On Jun-12-2013 07:25:20 AM

Don't want to miss updates? Please click the below button!

Follow MindStick