How to use Long Date ("D") Format Specifier
Description
The "D" standard format specifier is defined in DateTimeFormatInfo.LongDatePattern property.
For example, the custom format string for the invariant culture is "dddd, dd MMMM yyyy".
The following properties from DateTimeFormatInfo control the format.
- LongDatePattern
- DayNames
- MonthNames
Example
The following example uses the "D" format specifier to display a date and time value.
//from w w w. jav a 2s .com
using System;
using System.Globalization;
class MainClass
{
public static void Main()
{
DateTime date1 = new DateTime(2012, 4, 10);
Console.WriteLine(date1.ToString("D", CultureInfo.CreateSpecificCulture("en-US")));
Console.WriteLine(date1.ToString("D", CultureInfo.CreateSpecificCulture("pt-BR")));
Console.WriteLine(date1.ToString("D", CultureInfo.CreateSpecificCulture("es-MX")));
}
}
The code above generates the following result.