|
Web
News |

Canadians wary of online Christmas shopping A new national survey commissioned by Symantec Corp. and conducted by Decima Research finds that, while this country is one of the most connected in the world, only 24 per cent of Canadians plan to beat the crowds by shopping online this holiday season. Even more disconcerting for online merchants is the discovery...
Canada Invest $100 Million in Business Creation The Honourable Maxime Bernier, Canada's Minister of Industry and Minister responsible for the Business Development Bank of Canada (BDC), and Raymond Bachand, Quebec's Minister of Economic Development, Innovation and Export Trade, today announced the establishment of the GO Capital co-investment fund...
Feds overruling Net phone service decision Canada’s telecommunications giants finally got their wish Wednesday as federal Industry Minister Maxime Bernier confirmed Ottawa was overruling a CRTC decision to regulate the emerging technology of Internet-based phone service. The Canadian Radio-television and Telecommunications Commission made the decision...
Satellite v/s digital radio: A divided world In the last few years, three companies have taken the global radio industry by storm—Sirius, XM and Worldspace. What is common between them is that they are broadcasters of satellite radio—a technology that is proving to be more than a match to terrestrial radio, which uses the analogue mode to broadcast AM and FM stations. A recently-released PricewaterhouseCoopers...
Cable deal to come under scrutiny as house reopens Government handling of a fibre optic deal will likely take centre stage as Newfoundland and Labrador politicians return Monday for the first sitting since a legislative spending scandal broke in June. Premier Danny Williams has been accused of cronyism for putting $15 million into a fibre optic network backed by former business associates.
|
|
 |
|
11.20.06
Converting A Date To RFC822 For RSS Use
By Mads Kristensen
I wrote a new dynamic RSS feed for a little project called Little Helper. It all works fine, but when I tried to validate it using FeedValidator, the pubDate was invalid.
The validator told me that the date was not proper formatted using the RFC822 standard which looks something like this:
Wed, 27 Sep 2006 21:36:45 +0200.
Ok, that's no problem right? Just format the DateTime correctly and you're ready to go. Wrong!
This is what happens if you try to do just that:
DateTime.Now.ToString("r")
The output of that is:
Wed, 27 Sep 2006 21:49:19 GMT
GMT is an acceptable value for RFC822, but not for my location which should be +0200. It fails on all the machines I tried it on. If I then try to write the format string manually like this, it still doesn't work.
DateTime.Now.ToString("ddd, dd MMM yyyy HH:mm:ss zzzz")
The output of that is:
Wed, 27 Sep 2006 21:36:45 +02:00
It is almost correct, but the time zone is not formatted correctly. After searching the web, it became clear that .NET does not let you format the DateTime to the RFC822 by its standard formatters. So, I had to write a little method that did just that.
/// <summary>
/// Converts a regular DateTime to a RFC822 date string.
/// </summary>
/// <returns>The specified date formatted as a RFC822 date string.</returns>
private static string GetRFC822Date(DateTime date)
{
int offset = TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now).Hours;
string timeZone = "+" + offset.ToString().PadLeft(2, '0');
if (offset < 0)
{
int i = offset * -1;
timeZone = "-" + i.ToString().PadLeft(2, '0');
}
return date.ToString("ddd, dd MMM yyyy HH:mm:ss " + timeZone.PadRight(5, '0'));
}
Just give it a DateTime and it will return a properly formatted RFC822 string that will validate.
Response.Write(GetRFC822Date(DateTime.Now));
Note, that the RSS feed probably works fine without using a method like this, even though the FeedValidator doesn't agree. At the end of the day, the feed validated.
About the Author:
Mads Kristensen currently works as a Senior Developer at Traceworks located
in Copenhagen, Denmark. Mads graduated from Copenhagen Technical Academy with a multimedia degree in
2003, but has been a professional developer since 2000. His main focus is on ASP.NET but is responsible for Winforms, Windows- and
web services in his daily work as well. A true .NET developer with great passion for the simple solution.
http://www.madskristensen.dk/
|
|