I need to parse and add to database dates from RSS feed. There's a problem, that one has "Wed, 08 May 2013 17:03:44 EDT", other with EST, other with CET, other "Mon, 23 Dec 2013 21:45:32 +0200". Parsing fails when it receives EDT. This is because I used:
CultureInfo provider = CultureInfo.InvariantCulture;
var format = "ddd, dd MMM yyyy hh:mm:ss EST";
DateTime postTime;
//<... make f.pubDate to have date string ...>
var convertionResult = DateTime.TryParse(f.pubDate, out postTime);
if (!convertionResult)
{
postTime = DateTime.ParseExact(f.pubDate, format, provider);
//<...>
};
Is there any universal method to do that, I'm definitely missing something :)
Thanks!
I don't believe there's anything in the .NET framework which will parse time zone abbreviations - and for fairly good reason, given that they're not globally unique. It's a shame that RSS used such a brain-dead date/time format, to be honest.
You might be best having a lookup table from "time zone abbreviation" to "time zone offset".
It's possible that the "zzz" part of a custom date and time format would parse the "+0200" part - with Noda Time you could specify that explicitly. If .NET doesn't handle it immediately, you could just add a colon in the right place at which point it would be okay.
Another alternative would be to find an existing RSS parser which does all this for you - I'm sure you're not the first person to face this issue.
See more on this question at Stackoverflow