C# DateTime GetDateTimeFormats()

Description

DateTime GetDateTimeFormats() converts the value of this instance to all the string representations supported by the standard date and time format specifiers.

Syntax

DateTime.GetDateTimeFormats() has the following syntax.


public string[] GetDateTimeFormats()

Returns

DateTime.GetDateTimeFormats() method returns

Example

The following example demonstrates the DateTime.GetDateTimeFormats() method. It displays the string representation of a date using all possible standard date and time formats in the computer's current culture, which in this case is en-US.


using System;// w  w w . j  a va 2s.co m
public class MainClass{
  public static void Main(String[] argv){  
    DateTime july28 = new DateTime(2009, 7, 28, 5, 23, 15, 16);
    
    string[] july28Formats = july28.GetDateTimeFormats();
    
    // Print out july28 in all DateTime formats using the default culture. 
    foreach (string format in july28Formats) {
      System.Console.WriteLine(format);
    }
  }
}
    

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version