DateTime.GetDateTimeFormats Method ()
.NET Framework 3.0
Converts the value of this instance to all the string representations supported by the standard DateTime format specifiers.
Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly: mscorlib (in mscorlib.dll)
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];
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");
for (int iCtr2 = 0; iCtr2 < frenchJuly28Formats.get_Length(); iCtr2++) {
String format = frenchJuly28Formats[iCtr2];
System.Console.WriteLine(format);
}
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.Community Additions
ADD
Show: