TIMEZONE CLASS IN C#

Ankit Singh

Total Post:341

Points:2389
Posted by  Ankit Singh
C# 
C#
 994  View(s)
Ratings:
Rate this:
Can anyone provide me an example of TimeZone class?
  1. Vijay Shukla

    Post:100

    Points:700
    Re: TimeZone class in C#

    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

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!