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 ww.  j av a  2s.  c o  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/*  w w w .  jav a  2s  .  co  m*/
{
   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/*  w  w w.ja  v  a  2 s . c  o  m*/
{
    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