1

I am trying to load RSS feed http://feeds.feedburner.com/foxnews/latest but I am getting datetime parsing error in SyndicationFeed.Load() function because it is not able to parse Tue, 17 June 2014 02:38:06 EDT any suggestion?

I am already using this custom xml reader (http://brian-federici.com/blog/2012/9/21/exceptions-with-rss20feedformatterdatefromstring) to support multiple formats but still it is not supporting this format.

Can anyone help me that how to parse this Tue, 17 June 2014 02:38:06 EDT into DateTime object in C#

SOF User
  • 7,590
  • 22
  • 75
  • 121

1 Answers1

1

Use ParseExact (Note the 24 hour "HH")

CultureInfo provider = CultureInfo.InvariantCulture;
var myDate = DateTime.ParseExact("Tue, 17 June 2014 02:38:06 EDT", 
                                 "ddd, dd MMMM yyyy HH:mm:ss EDT", 
                                 provider);

The format codes are here

Per @Trisped's suggestion, here are the custom string formats

EDIT: Not sure why the "R" didnt work, but Custom works just fine.

Here's a Fiddle

crthompson
  • 15,653
  • 6
  • 58
  • 80
  • I knew there was a way to do that. Why didn't you add a link to the custom formats? – Trisped Jun 17 '14 at 21:35
  • 1
    your code has error ... Additional information: String was not recognized as a valid DateTime. – SOF User Jun 17 '14 at 21:41
  • 1
    The problem is that while [RFC 822/1123](http://www.w3.org/Protocols/rfc822/#z28) supports a handful of time zone abbreviations, like `EST` or `EDT` - the .Net implementation does not support them at all. By including EDT in the format here, it's just treating it as text and not adjusting for that time zone. See the answer I linked to the dup question. – Matt Johnson-Pint Jun 17 '14 at 21:52
  • @CmdrTallen, thanks, hope you find the answer useful. – crthompson Oct 16 '14 at 21:47