How to parse this date: "2003-10-29T17:44+00:00"

  • Thread starter Thread starter Muscha
  • Start date Start date
M

Muscha

Hello,

I have a date string in the following format: "2003-10-29T17:44+00:00"

When I put it to DateTime.Parse() method it throws an exception, how do I
parse this date format?

Thanks,

/m
 
In DateTime.Parse you need to specify the FormatInfo. Create a custom
FormatInfo that defines the format you are using and when trying to use
DateTime.Parse() specify that format info

Thanks,
Jagan Mohan
 
That format looks a lot like a xml date time format. Maybe you could try the
XmlConvert.ToDateTime() method in the System.Xml namespace.
 
An alternative would be to do a string replace on the T
character, as replacing this with a space will allow it
to parse normally.

e.g. this works

string s = "2002-10-31T12:30+01:00";
s = s.Replace("T", " ");
t = DateTime.Parse(s);

Sam
 
Muscha,
Have you looked at DateTime.ParseExact with a custom format?

Something like (minimally tested in VB.NET):

string format = "yyyy-MM-ddTHH:mmzzz";
string s = "2003-10-29T17:44+00:00";

DateTime d = DateTime.ParseExact(s, format, null);

Which is very close to the "s" & "u" standard formats, except for the time
zone on the end...

Hope this helps
Jay
 
Back
Top