using System;
public class MainClass {
public static void Main() {
TimeZoneInfo zone = TimeZoneInfo.Local;
Console.WriteLine(zone.StandardName);
Console.WriteLine(zone.DaylightName);
}
}
Month: February 2011
The Id property corresponds to the value passed to FindSystemTimeZoneById.
using System;
public class MainClass {
public static void Main() {
foreach (TimeZoneInfo z in TimeZoneInfo.GetSystemTimeZones())
Console.WriteLine(z.Id);
}
}
Convert To TimeZone
//Octavalent Extension Methods
//http://sdfasdf.codeplex.com/
//Library of extension methods for .Net create by Octavalent (www.octavalent.nl)
using System;
public static class DateTimeExtensions
{
public static DateTime ConvertToTimeZone(this DateTime dateTime, string SystemTimeZoneId)
{
dateTime = dateTime.ToUniversalTime();
dateTime = dateTime.Add(TimeZoneInfo.FindSystemTimeZoneById(SystemTimeZoneId).GetUtcOffset(dateTime));
return dateTime;
}
}
The static TimeZone.CurrentTimeZone method returns a TimeZone object based on the current local settings
using System;
public class MainClass {
public static void Main() {
TimeZone zone = TimeZone.CurrentTimeZone;
Console.WriteLine(zone.StandardName);
Console.WriteLine(zone.DaylightName);
}
}
The GetDaylightChanges method returns specific daylight saving information for a given year:
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);
}
}
The IsDaylightSavingTime and GetUtcOffset methods work as follows:
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));
}
}
Initalize a timespan to 25 milliseconds
using System;
public class ToString
{
public static void Main()
{
TimeSpan span;
span = new TimeSpan(0, 0, 0, 0, 25);
}
}

