using System;
using System.Text;
class Sample
{
public static void Main()
{
TimeZone zone = TimeZone.CurrentTimeZone;
DateTime dt1 = new DateTime(2008, 1, 1);
Console.WriteLine(zone.GetUtcOffset(dt1));
}
}
The output:
-08:00:00
TimeZoneInfo GetUtcOffset method accepts either a DateTime or a DateTimeOffset.
using System;
using System.Text;
using System.Globalization;
class Sample
{
public static void Main()
{
TimeZoneInfo zone = TimeZoneInfo.Local;
DateTime dt1 = new DateTime(2008, 1, 1);
Console.WriteLine(zone.GetUtcOffset(dt1));
DateTime dtf = new DateTime(2008, 1, 1);
Console.WriteLine(zone.GetUtcOffset(dtf));
}
}
The output:
-08:00:00
-08:00:00