C# DateTimeOffset Offset

Description

DateTimeOffset Offset gets the time's offset from Coordinated Universal Time (UTC).

Syntax

DateTimeOffset.Offset has the following syntax.


public TimeSpan Offset { get; }

Example

The following example uses the Offset property to display the local time's difference from Coordinated Universal Time (UTC).


//from ww w .j av  a 2  s  .c om
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 »
    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