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.





















Home »
  C# Tutorial »
    Data Types »




C# Data Types
Bool
Byte
Char
Decimal
Double
Float
Integer
Long
Short
String
C# Array
Array Example
Byte Array
C# Standard Data Type Format
BigInteger
Complex
Currency
DateTime
DateTimeOffset
DateTime Format Parse Convert
TimeSpan
TimeZone
Enum
Null
tuple
var