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.