blog.x-e.ro / RFC822 compliant dates for rss feeds : in php and asp.net

RFC822 compliant dates for rss feeds

php :: in php and asp.net

with the advent of web-syndication, a few different feed protocols have evolved (rss and atom being the most popular). because of their growth in popularity the protocol to create a feed has become more stringent. luckily we have validators who help us keep our feeds on the right track. one of these guidelines is RFC822 compliant dates. these dates look like Sat, 14 Jul 2007 18:40:26 -0400. formatting your data to be compliant with this standard can be challenging, so i have written some code to help you along... 

Creating a RFC822 compliant date in php is a snap...

$rssDate = date("r");

in asp.net this is a bit more tricky. microsoft doesn't have a native RFC822 date format, so we are going to have to convert our dateTime.now() into that format:

public string dateFormat(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 yyy HH:mm:ss " + timeZone.PadRight(5, '0'));
}
loading...

loading...