Reputation:
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
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
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
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