C# DateTime GetDateTimeFormats (IFormatProvider)
Description
DateTime GetDateTimeFormats(IFormatProvider)
converts
the value of this instance to all the string representations supported by
the standard date and time format specifiers and the specified culture-specific
formatting information.
Syntax
DateTime.GetDateTimeFormats(IFormatProvider)
has the following syntax.
public string[] GetDateTimeFormats(
IFormatProvider provider
)
Parameters
DateTime.GetDateTimeFormats(IFormatProvider)
has the following parameters.
provider
- An object that supplies culture-specific formatting information about this instance.
Returns
DateTime.GetDateTimeFormats(IFormatProvider)
method returns
Example
The following example demonstrates the DateTime.GetDateTimeFormats(IFormatProvider) method. It displays the string representation of a date using all possible standard date and time formats for the fr-FR culture.
using System;//from w ww .jav a2s . c om
public class MainClass{
public static void Main(String[] argv){
DateTime july28 = new DateTime(2009, 7, 28, 5, 23, 15, 16);
IFormatProvider culture =
new System.Globalization.CultureInfo("fr-FR", true);
// Get the short date formats using the "fr-FR" culture.
string [] frenchJuly28Formats =
july28.GetDateTimeFormats(culture);
// Display july28 in various formats using "fr-FR" culture.
foreach (string format in frenchJuly28Formats) {
System.Console.WriteLine(format);
}
}
}
The code above generates the following result.