Convert DateTime to all string representations supported by the standard date and time format and the specified culture in CSharp
Description
The following code shows how to convert DateTime to all string representations supported by the standard date and time format and the specified culture.
Example
using System;//w w w . jav a2 s. co m
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.