Of Code and Me

Somewhere to write down all the stuff I'm going to forget and then need

Format a string in RFC 2822 format for use with Http headers in c# March 17, 2010

Filed under: Asp.Net,C#,Coding,Web — Rupert Bates @ 11:45 am
var lastModified = AppStart.ToString("ddd, dd MMM yyyy hh:mm:ss ") + "GMT"; //note the hard coded GMT, there doesn't seem to be any other way to get this

Custom Date and Time Format Strings on MSDN
Standard Date and Time Format Strings on MSDN

 

2 Responses to “Format a string in RFC 2822 format for use with Http headers in c#”

  1. JT Says:

    This is incorrect. It should use a 24 hour clock. HH instead of hh. It should be noted that this is the exact format string for the “r” format string.
    var lastModified = AppStart.ToString(“r”);

    Be sure the time is in UTC timezone.

    Also, RFC 2822 allows other timezones to be specified, but it’s simpler to just use this format.


Leave a reply to Rupert Bates Cancel reply