C# DateTimeOffset ToString()

Description

DateTimeOffset ToString() converts the value of the current DateTimeOffset object to its equivalent string representation.

Syntax

DateTimeOffset.ToString() has the following syntax.


public override string ToString()

Returns

DateTimeOffset.ToString() method returns A string representation of a DateTimeOffset object that includes the offset appended at the end of the string.

Example

The following example illustrates calls to the ToString() method and displays its output on a system whose current culture is en-us.


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