7

I'm trying to pull a DateTime object from RSS feeds in C# and DateTime.Parse(string) was working fine for the BBC rss feed which has a format like: Thu, 24 Sep 2009 13:08:30 GMT

But when I try and use that for Engadget's feed which has a date format like Thu, 24 Sep 2009 17:04:00 EST throws a FormatException.

Is there something straight forward that I'm missing here?

3 Answers3

5

DateTime.Parse doesn't understand EST. It only understands GMT on the end of the string.

Standard Date and Time Format Strings Link: http://msdn.microsoft.com/en-us/library/az4se3k1.aspx

Here's an SO link to help... EST and such are not recognized. You will have to convert them to the time offsets:

Parse DateTime with time zone of form PST/CEST/UTC/etc

Community
  • 1
  • 1
Kevin LaBranche
  • 20,908
  • 5
  • 52
  • 76
5

Parsing dates in RSS feeds is VERY frustrating. I came across a fantastic free library called the Argotic Syndication Framework on CodePlex. It works like a champ and also supports ATOM feeds. Returns a nice little dataset from a feed, including a standard date.

1

Just wrote this, someone else might find it useful.

/// <summary>
/// Converts c# DateTime object into pubdate format for RSS
/// Desired format: Mon, 28 Mar 2011 02:51:23 -0700
/// </summary>
/// <param name="Date">DateTime object to parse</param>
/// <returns>Formatted string in correct format</returns>
public static string PubDate(DateTime Date)
{
    string ReturnString = Date.DayOfWeek.ToString().Substring(0,3) + ", ";
    ReturnString += Date.Day + " ";
    ReturnString += CultureInfo.CurrentCulture.DateTimeFormat.GetAbbreviatedMonthName(Date.Month) + " ";
    ReturnString += Date.Year + " ";
    ReturnString += Date.TimeOfDay + " -0700";

    return ReturnString;
}
Tom Gullen
  • 61,249
  • 84
  • 283
  • 456