Export (0) Print
Expand All

DateTime.GetDateTimeFormats Method

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

Overload List

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

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Function GetDateTimeFormats() As String()
[C#] public string[] GetDateTimeFormats();
[C++] public: String* GetDateTimeFormats() __gc[];
[JScript] public function GetDateTimeFormats() : String[];

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

Supported by the .NET Compact Framework.

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

Converts the value of this instance to all the string representations supported by the standard DateTime format specifiers and the specified culture-specific formatting information.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Function GetDateTimeFormats(IFormatProvider) As String()
[C#] public string[] GetDateTimeFormats(IFormatProvider);
[C++] public: String* GetDateTimeFormats(IFormatProvider*) __gc[];
[JScript] public function GetDateTimeFormats(IFormatProvider) : String[];

Converts the value of this instance to all the string representations supported by the specified standard DateTime format specifier and culture-specific formatting information.

Supported by the .NET Compact Framework.

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

Example

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

[Visual Basic, C#, C++] Note   This example shows how to use one of the overloaded versions of GetDateTimeFormats. For other examples that might be available, see the individual overload topics.
[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.

See Also

DateTime Structure | DateTime Members | System Namespace

Show:
© 2014 Microsoft