C# DateTimeOffset Offset
Description
DateTimeOffset Offset
gets the time's offset from Coordinated
Universal Time (UTC).
Syntax
DateTimeOffset.Offset
has the following syntax.
public TimeSpan Offset { get; }
Example
The following example uses the Offset property to display the local time's difference from Coordinated Universal Time (UTC).
//from ww w .j av a 2 s .c om
using System;
public class MainClass{
public static void Main(String[] argv){
DateTimeOffset localTime = DateTimeOffset.Now;
Console.WriteLine("The local time zone is {0} hours and {1} minutes {2} than UTC.",
Math.Abs(localTime.Offset.Hours),
localTime.Offset.Minutes,
localTime.Offset.Hours < 0 ? "earlier" : "later");
}
}
The code above generates the following result.