DateTime.GetDateTimeFormats Method (Char)

Converts the value of this instance to all the string representations supported by the specified standard DateTime format specifier.

Namespace: System
Assembly: mscorlib (in mscorlib.dll)

array<String^>^ GetDateTimeFormats (
	wchar_t format
public String[] GetDateTimeFormats (
	char format
public function GetDateTimeFormats (
	format : char
) : String[]
Not applicable.



A DateTime format string.

Return Value

A string array where each element is the representation of the value of this instance formatted with the format standard DateTime formatting specifier.

Each element of the return value is formatted using information from the current culture. For more information about culture-specific formatting information for the current culture, see CultureInfo.CurrentCulture.

For more information about the standard formatting specifiers, see System.Globalization.DateTimeFormatInfo.

The following code example demonstrates the GetDateTimeFormats method.

   DateTime july28 = DateTime(1979,7,28,5,23,15,16);
   array<String^>^july28Formats = july28.GetDateTimeFormats();
   // Print [Out] july28* in all DateTime formats using the
   // default culture.
   System::Collections::IEnumerator^ myEnum = july28Formats->GetEnumerator();
   while ( myEnum->MoveNext() )
      String^ format = safe_cast<String^>(myEnum->Current);
      System::Console::WriteLine( format );

   IFormatProvider^ culture = gcnew System::Globalization::CultureInfo( "fr-FR",true );
   // Get the short date formats using the S"fr-FR" culture.
   array<String^>^frenchJuly28Formats = july28.GetDateTimeFormats( 'd', culture );
   // Print [Out] july28* in various formats using S"fr-FR" culture.
   System::Console::WriteLine( "Starting fr-FR formats" );
   System::Collections::IEnumerator^ myEnum2 = frenchJuly28Formats->GetEnumerator();
   while ( myEnum2->MoveNext() )
      String^ format = safe_cast<String^>(myEnum2->Current);
      System::Console::WriteLine( format );

This example produces the following results:

Is Thursday the day of the week for 5/1/2003?: True
The day of the week for 5/1/2003 is Thursday.

DateTime july28 = new DateTime(1979, 7, 28, 5, 23, 15, 16);
String july28Formats[] = july28.GetDateTimeFormats();

// Print out july28 in all DateTime formats using the
// default culture.
for (int iCtr1 = 0; iCtr1 < july28Formats.get_Length(); iCtr1++) {
    String format = july28Formats[iCtr1];
IFormatProvider culture = new System.Globalization.CultureInfo("fr-FR",

// Get the short date formats using the "fr-FR" culture.
String frenchJuly28Formats[] = july28.GetDateTimeFormats('d', culture);

// Print out july28 in various formats using "fr-FR" culture.
System.Console.WriteLine("Starting fr-FR formats");
for (int iCtr2 = 0; iCtr2 < frenchJuly28Formats.get_Length(); iCtr2++) {
    String format = frenchJuly28Formats[iCtr2];

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0

Community Additions