Convert DateTimeOffset to a DateTimeOffset representing the Coordinated Universal Time (UTC) in CSharp
Description
The following code shows how to convert DateTimeOffset to a DateTimeOffset representing the Coordinated Universal Time (UTC).
Example
//from w ww .j a v a 2 s . c o m
using System;
public class MainClass{
public static void Main(String[] argv){
DateTimeOffset localTime, otherTime;
localTime = new DateTimeOffset(new DateTime(2014, 6, 15, 12, 0, 0));
Console.WriteLine("Local time: {0}", localTime);
Console.WriteLine();
// Convert local time to offset 0 and assign to otherTime
otherTime = localTime.ToOffset(TimeSpan.Zero);
Console.WriteLine("Other time: {0}", otherTime);
Console.WriteLine("{0} = {1}: {2}",
localTime, otherTime,
localTime.Equals(otherTime));
Console.WriteLine("{0} exactly equals {1}: {2}",
localTime, otherTime,
localTime.EqualsExact(otherTime));
}
}
The code above generates the following result.