CSharp - Date Time TimeZone Type

Introduction

TimeZone.CurrentTimeZone method returns a TimeZone object based on the current local settings.

The following demonstrates the result if run in California:

Demo

using System;
class MainClass//from w w  w .j a  va  2  s  .co  m
{
   public static void Main(string[] args)
   {
     TimeZone zone = TimeZone.CurrentTimeZone;
     Console.WriteLine (zone.StandardName);      
     Console.WriteLine (zone.DaylightName);      

   }
}

Result

The IsDaylightSavingTime and GetUtcOffset methods work as follows:

Demo

using System;
class MainClass/*from  w ww.  j  a  v  a 2 s. c  om*/
{
   public static void Main(string[] args)
   {
     TimeZone zone = TimeZone.CurrentTimeZone;
     DateTime dt1 = new DateTime (2015, 1, 1);
     DateTime dt2 = new DateTime (2015, 6, 1);
     Console.WriteLine (zone.IsDaylightSavingTime (dt1));     // True
     Console.WriteLine (zone.IsDaylightSavingTime (dt2));     // False
     Console.WriteLine (zone.GetUtcOffset (dt1));             // 08:00:00
     Console.WriteLine (zone.GetUtcOffset (dt2));             // 09:00:00

   }
}

Result

GetDaylightChanges method returns specific daylight saving time information for a given year:

Demo

using System;
using System.Globalization;

class MainClass/*from  www  .  jav  a  2  s  .  c  om*/
{
    public static void Main(string[] args)
    {
        TimeZone zone = TimeZone.CurrentTimeZone;
        DaylightTime day = zone.GetDaylightChanges(2015);
        Console.WriteLine(day.Start.ToString("M"));       // 08 March
        Console.WriteLine(day.End.ToString("M"));         // 01 November
        Console.WriteLine(day.Delta);                      // 01:00:00
    }
}

Result