C# DateTime GetDateTimeFormats(Char, IFormatProvider)
Description
DateTime GetDateTimeFormats(Char, IFormatProvider)
converts
the value of this instance to all the string representations supported by
the specified standard date and time format specifier and culture-specific
formatting information.
Syntax
DateTime.GetDateTimeFormats(Char, IFormatProvider)
has the following syntax.
public string[] GetDateTimeFormats(
char format,
IFormatProvider provider
)
Parameters
DateTime.GetDateTimeFormats(Char, IFormatProvider)
has the following parameters.
format
- A date and time format string (see Remarks).provider
- An object that supplies culture-specific formatting information about this instance.
Returns
DateTime.GetDateTimeFormats(Char, IFormatProvider)
method returns
Example
The following example demonstrates the GetDateTimeFormats(Char, IFormatProvider) method.
It displays the string representations of a date using the short date format specifier ("d") for the fr-FR culture.
using System;/*w w w . j a v a 2 s . c o m*/
public class MainClass{
public static void Main(String[] argv){
DateTime july28 = new DateTime(2009, 7, 28, 5, 23, 15);
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);
// Display july28 in short date formats using "fr-FR" culture.
foreach (string format in frenchJuly28Formats) {
System.Console.WriteLine(format);
}
}
}
The code above generates the following result.