Create DateTime from string supported by the standard date and time format specifiers in CSharp

Description

The following code shows how to create DateTime from string supported by the standard date and time format specifiers.

Example


/* w w  w.j a  v  a 2  s  .  c om*/
using System;
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 »
    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