Get the time's offset from Coordinated Universal Time (UTC) in CSharp

Description

The following code shows how to get the time's offset from Coordinated Universal Time (UTC).

Example


/*from  w  w  w.ja v a 2  s.  co m*/
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.





















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