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