Try to parse string("2009/03/01T10:00:00-5:00") to DateTime in CSharp
Description
The following code shows how to try to parse string("2009/03/01T10:00:00-5:00") to DateTime.
Example
using System;//from www. ja v a 2 s . c om
using System.Globalization;
public class MainClass{
public static void Main(String[] argv){
string dateString;
CultureInfo culture;
DateTimeStyles styles;
DateTime dateResult;
dateString = "2009/03/01T10:00:00-5:00";
styles = DateTimeStyles.AssumeLocal;
if (DateTime.TryParse(dateString, out dateResult))
System.Console.WriteLine("{0} converted to {1} {2}.",
dateString, dateResult, dateResult.Kind);
else
System.Console.WriteLine("Unable to convert {0} to a date and time.", dateString);
}
}
The code above generates the following result.