ToRFC822DateString
Converts a regular DateTime to a RFC822 date string used for RSS feeds
Source
/// <summary>
/// Converts a regular DateTime to a RFC822 date string.
/// </summary>
/// <returns>The specified date formatted as a RFC822 date string.</returns>
public static string ToRFC822DateString(this 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'), System.Globalization.CultureInfo.GetCultureInfo("en-US"));
}
Example
var s = DateTime.Now.ToRFC822DateString();