C# DateTimeOffset Now
Description
DateTimeOffset Now
gets a DateTimeOffset object that
is set to the current date and time on the current computer, with the offset
set to the local time's offset from Coordinated Universal Time (UTC).
Syntax
DateTimeOffset.Now
has the following syntax.
public static DateTimeOffset Now { get; }
Example
The following example uses the Now property to retrieve the current date and time and displays it by using each of the standard date and time format strings supported by the DateTimeOffset type.
using System;// w ww.jav a2s . c o m
public class Example
{
public static void Main()
{
String[] fmtStrings = { "d", "D", "f", "F", "g", "G", "M",
"R", "s", "t", "T", "u", "y" };
DateTimeOffset value = DateTimeOffset.Now;
foreach (var fmtString in fmtStrings)
Console.WriteLine("{0} --> {1}",
fmtString, value.ToString(fmtString));
}
}
The code above generates the following result.