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

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
 
J

Jagan Mohan

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
 
J

Jeroen Smits

That format looks a lot like a xml date time format. Maybe you could try the
XmlConvert.ToDateTime() method in the System.Xml namespace.
 
S

Sam

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
 
J

Jay B. Harlow [MVP - Outlook]

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top