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.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version