Try to parse string("03/01/2009T10:00:00-5:00") to DateTime in CSharp
Description
The following code shows how to try to parse string("03/01/2009T10:00:00-5:00") to DateTime.
Example
using System;/*w w w.jav a 2 s . c om*/
using System.Globalization;
public class MainClass
{
public static void Main(String[] argv)
{
string dateString;
DateTime dateResult;
// Attempt to convert a string in improper ISO 8601 format.
dateString = "03/01/2009T10:00:00-5:00";
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.