Parsing a complicated date time

C

campbell.mcneill

Hi,

I'm trying to parse the following date "Wed, 18 Dec 2002 08:01:23 +0100
(MET)".

I'm using the following code:

System.IFormatProvider format = new
System.Globalization.CultureInfo("sv-SE", true);
parsedDate = DateTime.ParseExact("Wed, 18 Dec 2002 08:01:23 +0100
(MET)", "dd MMM yyyy hh:mm:ss", format,
System.Globalization.DateTimeStyles.AllowWhiteSpaces);

But this leads to errors.

Anyone have any idea how I can parse this date without having to mash
the string up too much?

Thanks,

Campbell
 
C

Claes Bergefall

The string you have is language dependent and it's clearly not Swedish. Try
"en-US" instead and this format string:
@"ddd, dd MMM yyyy hh:mm:ss zzz \(\M\E\T\)"

Where do you get the string from?

/claes
 
C

campbell.mcneill

Claes,

That works a treat!

The string came in through some XML I got from a Swedish company.

I'm trying to tidy it up before I do anything with it in BizTalk.

Many thanks,

Campbell.
 
C

Claes Bergefall

If possible you should tell then to change the format to standard ISO (which
happens to be what Sweden uses anyway), i.e. "yyyy-MM-dd hh:mm:ss". Or even
better, tell them to use the standard XML date data type. Will make it a lot
easier for you. If that's not possible you can at least ask them how they
generate it. The sample you provided seems to have been generated with an
English culture, but that might just be a coincidence in this particular
case.

/claes
 

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