Emails generated by our applications were displaying universal time instead of a user’s local time when viewed in Thunderbird. Our servers use universal time. The emails we send to our users include a date header with UTC. Other email clients automatically convert this to the user’s local time.
I compared the date header in our messages to date headers in other messages in my inbox. I found that there were a variety of formats and wasn’t sure which one was correct, so I turned to the RFCs. I found RFC 4021 first, which referred to RFC 2822 and RFC 822. The proper “date-time” syntax was originally defined in RFC 822 section 5.1. and later clarified in RFC 2822 section 3.3.
Even the clarifications in RFC 2822 allowed several different formats, so I analyzed 132,037 date headers on one of our mail servers, hoping to determine if a specific format was most common. I found that the following format is by far the most common:
Date: Tue, 18 Nov 2014 15:57:11 +0000
The day of month and hour of day are both two digits. The time zone is a 4-digit offset prefixed with either a “+” or “-“. In the example above, the server is set to GMT or UTC, so the offset is “+0000”. Be aware that “+0000” and “-0000” are not handled the same! RFC 2822 section 3.3 says that offset “-0000” should be treated as an unknown timezone.
The following PHP code will output the format above:
echo "Date: " . date("D, d M Y H:i:s O");
It also seems acceptable to place the time zone or a comment in parenthesis after the date. Here are a few examples:
Date: Fri, 03 Dec 2010 16:02:30 -0600 (CST)
Date: Fri, 9 Sep 2005 16:38:47 -0400 (added by email@example.com)
I have attached the data file that contains 130,606 date headers (after removing 2k of mangled records that included other email contents) in case you would like to perform additional analysis.