Get DateTimeOffset whose date and time set to current Coordinated Universal Time (UTC) and whose offset is TimeSpan.Zero in CSharp

Description

The following code shows how to get DateTimeOffset whose date and time set to current Coordinated Universal Time (UTC) and whose offset is TimeSpan.Zero.

Example


using System;// ww  w  . j  a v  a  2  s  . 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 »
    Data Types »




C# Data Types
Bool
Byte
Char
Decimal
Double
Float
Integer
Long
Short
String
C# Array
Array Example
Byte Array
C# Standard Data Type Format
BigInteger
Complex
Currency
DateTime
DateTimeOffset
DateTime Format Parse Convert
TimeSpan
TimeZone
Enum
Null
tuple
var