Convert DateTimeOffset to string in CSharp

Description

The following code shows how to convert DateTimeOffset to string.

Example


// w  ww .j av  a 2 s  .com
using System;
public class MainClass{
  public static void Main(String[] argv){  
    DateTimeOffset thisDate = DateTimeOffset.UtcNow;
    Console.WriteLine(thisDate.ToString()); 
    
    thisDate = DateTimeOffset.Now;
    Console.WriteLine(thisDate.ToString());
    
    // Show output for arbitrary time offset
    thisDate = thisDate.ToOffset(new TimeSpan(-5, 0, 0));
    Console.WriteLine(thisDate.ToString());
    

  }
}

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