Export (0) Print
Expand All

DateTime.GetDateTimeFormats Method (IFormatProvider)

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.

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

public string[] GetDateTimeFormats (
	IFormatProvider provider
)
public String[] GetDateTimeFormats (
	IFormatProvider provider
)
public function GetDateTimeFormats (
	provider : IFormatProvider
) : String[]

Parameters

provider

An IFormatProvider that supplies culture-specific formatting information about this instance.

Return Value

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

Each element of the return value is formatted using culture-specific information supplied by provider.

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

Community Additions

ADD
Show:
© 2014 Microsoft