Convert String "2011-06-27T14:03:19.5300000+07:00" To Datetime
I have result string date xml export from database like "2011-06-27T14:03:19.5300000+07:00". How to Convert to format datetime fully(date and time) in C# or VB.Net langu开发者_开发知识库age datetime?
Please help me
Thanks in Advance
You can use DateTime.Parse
The DateTime.Parse(String) method tries to convert the string representation of a date and time value to its DateTime equivalent. The string to be parsed can take any of the following forms:
A string with a date and a time component.
A string with a date but no time component.
A string with a time but no date component.
A string that includes time zone information and conforms to ISO 8601. For example, the first of the following two strings designates the Coordinated Universal Time (UTC); the second designates the time in a time zone seven hours earlier than UTC:
2008-11-01T19:35:00.0000000Z
2008-11-01T19:35:00.0000000-07:00
A string that includes the GMT designator and conforms to the RFC 1123 time format. For example:
- Sat, 01 Nov 2008 19:35:00 GMT
A string that includes the date and time along with time zone offset information. For example:
- 03/01/2009 05:42:00 -5:00
DateTime dt = DateTime.Parse("2011-06-27T14:03:19.5300000+07:00");
The main point is to use DateTime.TryParse
string rawDate = "2011-06-27T14:03:19.5300000+07:00";
DateTime dt = DateTime.MinValue;
if (!DateTime.TryParse(rawDate, out dt))
{
Debug.WriteLine("Unable to parse");
}
If you're using XDocument
you can simply call conversion operator to DateTime
.
精彩评论