Tom A
Tom A

Reputation:

DateTime.Parse for pubDate in RSS Feeds

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?

Upvotes: 7

Views: 8026

Answers (3)

Tom Gullen
Tom Gullen

Reputation: 61737

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;
}

Upvotes: 1

user178744
user178744

Reputation:

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.

Upvotes: 5

Kevin LaBranche
Kevin LaBranche

Reputation: 21078

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

Upvotes: 5

Related Questions