Use the Parse() method to convert strings to DateTime instances: 1/11/2004 : DateTime Parse ParseExact « Date Time « C# / CSharp Tutorial






using System;

class MainClass
{
  public static void Main()
  {

    
    DateTime myDateTime5 = DateTime.Parse("1/11/2004");

    Console.WriteLine("myDateTime5 = " + myDateTime5);
  }

}
myDateTime5 = 01/11/2004 12:00:00 AM








13.4.DateTime Parse ParseExact
13.4.1.DateTime.Parse: Sep 2005
13.4.2.DateTime.Parse: Monday 5 September 2005 14:16:31
13.4.3.DateTime.Parse: 5,9,05
13.4.4.DateTime.Parse: 5/9/2005 14:15:33
13.4.5.DateTime.Parse: 2:15 PM
13.4.6.DateTime.ParseExact: (2:13:30 PM, h:mm:ss tt, null)
13.4.7.DateTime.ParseExact: Mon, 05 Sep 2005 14:13:30 GMT, ddd, dd MMM yyyy HH':'mm':'ss 'GMT', null
13.4.8.DateTime.ParseExact: September 05, MMMM dd, null
13.4.9.Use the Parse() method to convert strings to DateTime instances: 1/11/2004
13.4.10.Use the Parse() method to convert strings to DateTime instances: 1/11/2004 23:10:30
13.4.11.DateTime.Parse and DateTime.Kind
13.4.12.Parse string with date but no time component