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

Advertisements
 

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

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s