C# DateTimeOffset UtcNow
Description
DateTimeOffset UtcNow
gets a DateTimeOffset object
whose date and time are set to the current Coordinated Universal Time (UTC)
date and time and whose offset is TimeSpan.Zero.
Syntax
DateTimeOffset.UtcNow
has the following syntax.
public static DateTimeOffset UtcNow { get; }
Example
The following example illustrates the relationship between Coordinated Universal Time (UTC) and local time.
using System;// ww w.j a v a 2s .c o m
public class MainClass{
public static void Main(String[] argv){
DateTimeOffset localTime = DateTimeOffset.Now;
DateTimeOffset utcTime = DateTimeOffset.UtcNow;
Console.WriteLine("Local Time: {0}", localTime.ToString("T"));
Console.WriteLine("Difference from UTC: {0}", localTime.Offset.ToString());
Console.WriteLine("UTC: {0}", utcTime.ToString("T"));
}
}
The code above generates the following result.