C# DateTimeOffset Date
Description
DateTimeOffset Date
gets a DateTime value that represents
the date component of the current DateTimeOffset object.
Syntax
DateTimeOffset.Date
has the following syntax.
public DateTime Date { get; }
Example
The following example retrieves the value of the Date property for a specific date. It then displays that value to the console using some standard and custom date-only format specifiers.
/*from ww w. ja va2 s . c om*/
using System;
public class MainClass{
public static void Main(String[] argv){
DateTimeOffset thisDate = new DateTimeOffset(2014, 3, 17, 1, 32, 0, new TimeSpan(-5, 0, 0));
string fmt; // format specifier
fmt = "D";
Console.WriteLine("'{0}' format specifier: {1}",
fmt, thisDate.Date.ToString(fmt));
fmt = "d";
Console.WriteLine("'{0}' format specifier: {1}",
fmt, thisDate.Date.ToString(fmt));
fmt = "Y";
Console.WriteLine("'{0}' format specifier: {1}",
fmt, thisDate.Date.ToString(fmt));
fmt = "dd MMM yyyy";
Console.WriteLine("'{0}' format specifier: {1}",
fmt, thisDate.Date.ToString(fmt));
}
}
The code above generates the following result.