C# DateTime GetDateTimeFormats(Char)
Description
DateTime GetDateTimeFormats(Char)
converts the value
of this instance to all the string representations supported by the specified
standard date and time format specifier.
Syntax
DateTime.GetDateTimeFormats(Char)
has the following syntax.
public string[] GetDateTimeFormats(
char format
)
Parameters
DateTime.GetDateTimeFormats(Char)
has the following parameters.
format
- A standard date and time format string (see Remarks).
Returns
DateTime.GetDateTimeFormats(Char)
method returns
Example
The following example demonstrates the GetDateTimeFormats(Char) method. It displays the string representation of a date using the long date format specifier ("D") for the current culture.
using System;/*from w ww. j a v a2 s. c o m*/
public class MainClass{
public static void Main(String[] argv){
DateTime july28 = new DateTime(2009, 7, 28, 5, 23, 15);
// Get the long date formats using the current culture.
string [] longJuly28Formats =
july28.GetDateTimeFormats('D');
// Display july28 in all long date formats.
foreach (string format in longJuly28Formats) {
System.Console.WriteLine(format);
}
}
}
The code above generates the following result.