This documentation is archived and is not being maintained.

DateTime.GetDateTimeFormats Method (Char)

.NET Framework 1.1

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

[Visual Basic]
Overloads Public Function GetDateTimeFormats( _
   ByVal format As Char _
) As String()
[C#]
public string[] GetDateTimeFormats(
 char format
);
[C++]
public: String* GetDateTimeFormats(
 __wchar_t format
)  __gc[];
[JScript]
public function GetDateTimeFormats(
   format : Char
) : String[];

Parameters

format
A Unicode character containing a format specifier.

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.

Remarks

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.

Example

[Visual Basic, C#, C++] The following sample demonstrates the GetDateTimeFormats method.

[Visual Basic] 
Dim july28 As New DateTime(1979, 7, 28, 5, 23, 15, 16)

Dim july28Formats As String()
july28Formats = july28.GetDateTimeFormats()

' Print out july28 in all DateTime formats using the
' default culture.
Dim format As String
For Each format In july28Formats
   System.Console.WriteLine(format)
Next format

Dim culture As New System.Globalization.CultureInfo("fr-FR", True)

Dim frenchJuly28Formats As String()
' Get the short date formats using the "fr-FR" culture.
frenchJuly28Formats = july28.GetDateTimeFormats("d"c, culture)

' Print out july28 in various formats using "fr-FR" culture.
System.Console.WriteLine("Starting fr-FR formats")
For Each format In frenchJuly28Formats
   System.Console.WriteLine(format)
Next format

[C#] 
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.
foreach (string format in july28Formats) {
    System.Console.WriteLine(format);
}

IFormatProvider culture = 
    new System.Globalization.CultureInfo("fr-FR", true);
// 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");
foreach (string format in frenchJuly28Formats) {
    System.Console.WriteLine(format);
}

[C++] 
DateTime july28 = DateTime(1979, 7, 28, 5, 23, 15, 16);

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 = __try_cast<String*>(myEnum->Current);

   System::Console::WriteLine(format);
}

IFormatProvider* culture = new System::Globalization::CultureInfo(S"fr-FR", true);
// Get the short date formats using the S"fr-FR" culture.
String* frenchJuly28Formats[] =
   july28.GetDateTimeFormats('d', culture);

// Print [Out] july28* in various formats using S"fr-FR" culture.
System::Console::WriteLine(S"Starting fr-FR formats");
System::Collections::IEnumerator* myEnum2 = frenchJuly28Formats->GetEnumerator();
while (myEnum2->MoveNext()) {
   String* format = __try_cast<String*>(myEnum2->Current);

   System::Console::WriteLine(format);
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

DateTime Structure | DateTime Members | System Namespace | DateTime.GetDateTimeFormats Overload List

Show: