Mega Code Archive

 
Categories / C# Tutorial / Date Time
 

Use standard en-US date and time value to do Date time parse

using System; using System.Globalization; public class DateTimeParser {    public static void Main()    {       DateTime dateValue;       string dateString = "2/16/2010 12:15:12 PM";       try {          dateValue = DateTime.Parse(dateString);          Console.WriteLine("'{0}' converted to {1}.", dateString, dateValue);       }          catch (FormatException) {          Console.WriteLine("Unable to convert '{0}'.", dateString);       }    } }