Csharp/C Sharp/Development Class/TimeZone

Материал из .Net Framework эксперт
Перейти к: навигация, поиск

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

<source lang="csharp"> using System; using System.Globalization; public class MainClass {

   public static void Main() {
       TimeZone zone = TimeZone.CurrentTimeZone;
       DaylightTime day = zone.GetDaylightChanges(2008);
       Console.WriteLine(day.Start);
       Console.WriteLine(day.End);
       Console.WriteLine(day.Delta);
   }

}

</source>


The IsDaylightSavingTime and GetUtcOffset methods work as follows:

<source lang="csharp"> using System; public class MainClass {

   public static void Main() {
       TimeZone zone = TimeZone.CurrentTimeZone;
       DateTime dt1 = new DateTime(2008, 1, 1);
       DateTime dt2 = new DateTime(2008, 6, 1);
       Console.WriteLine(zone.IsDaylightSavingTime(dt1));
       Console.WriteLine(zone.IsDaylightSavingTime(dt2));
       Console.WriteLine(zone.GetUtcOffset(dt1));
       Console.WriteLine(zone.GetUtcOffset(dt2));
   }

}

</source>


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

<source lang="csharp">

using System; public class MainClass {

   public static void Main() {
       TimeZone zone = TimeZone.CurrentTimeZone;
       Console.WriteLine(zone.StandardName);
       Console.WriteLine(zone.DaylightName);
   }

}

</source>