[edit] Using the DateTime.GetDateTimeFormats Method
To use the DateTime.GetDateTimeFormats method you will need a datetime object already established. GetDateTimeFormats will simply return the available formats for your given object. There are four overloaded versions of the GetDateTimeFormats method.
[edit] Syntax
object.GetDateTimeFormats()
[edit] Example 1:
Lets print certain date formats
using System;
class Program
{
static void Main()
{
DateTime today = DateTime.Now;
string[] form = today.GetDateTimeFormats();
Console.WriteLine(form[2].ToString());
Console.WriteLine(form[3].ToString());
Console.WriteLine(form[4].ToString());
Console.WriteLine(form[5].ToString());
Console.WriteLine(form[11].ToString());
Console.Read();
}
}
Output:
[edit] Example 2:
Lets print all the available formats
using System;
class Program
{
static void Main()
{
DateTime today = DateTime.Now;
string[] form = today.GetDateTimeFormats();
foreach (string date in form)
Console.WriteLine(date);
Console.Read();
}
}
Output:
This code prints every available format. The program simply stores all the formats in a string array then goes on to print all the strings.
<-- DateTime Tutorial
|