How to use Short Date ("d") Format Specifier
Description
The "d" standard format specifier is from DateTimeFormatInfo.ShortDatePattern property. For example, the ShortDatePattern property of the invariant culture is "MM/dd/yyyy".
The following table lists the DateTimeFormatInfo object properties that control the formatting.
- ShortDatePattern
- DateSeparator
Example
The following example uses the "d" format specifier to display a date and time value.
/*from w ww . ja v a 2s . co m*/
using System;
using System.Globalization;
class MainClass
{
public static void Main()
{
DateTime date1 = new DateTime(2010,5, 21);
Console.WriteLine(date1.ToString("d", DateTimeFormatInfo.InvariantInfo));
Console.WriteLine(date1.ToString("d", CultureInfo.CreateSpecificCulture("en-US")));
Console.WriteLine(date1.ToString("d", CultureInfo.CreateSpecificCulture("en-NZ")));
Console.WriteLine(date1.ToString("d", CultureInfo.CreateSpecificCulture("de-DE")));
}
}
The code above generates the following result.