Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

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)

public string[] GetDateTimeFormats (
	char format
)
public String[] GetDateTimeFormats (
	char format
)
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.

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 = 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);
}

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 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 .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft