Get a DateTime value that represents the date component of the current DateTimeOffset in CSharp
Description
The following code shows how to get a DateTime value that represents the date component of the current DateTimeOffset.
Example
using System;/*from w w w. j a va2 s.c o m*/
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.