Erlang Central

Difference between revisions of "RFC1123 Dates and Times"

From ErlangCentral Wiki

m (Reverted edits by Kaiserpanda (Talk); changed back to last version by Bfulgham)
(One intermediate revision by one user not shown)

Revision as of 08:50, 4 December 2006


You need to convert from an Erlang Date or Time tuple to RFC 1123 format Dates and Times.


The Erlang httpd_util module provides a solution:

1> CurrTime = erlang:universaltime().
2> httpd_util:rfc1123_date(CurrTime).
"Sat, 28 Aug 2004 08:15:38 GMT"

Most applications that use RFC 1123 or RFC 822 time formats require all output in GMT. However, Erlang does not provide support for RFC 822 formatted time, since it assumes all input times are GMT.

3> LocalTime = erlang:localtime().
4> httpd_util:rfc1123_date(LocalTime).
"Sat, 28 Aug 2004 01:19:37 GMT"

If you need to parse dates as input, you can use httpd_util:convert_request_date function:

5> DateString = "Wed, 28 Apr 2004 17:22:10 Z".
"Wed, 28 Apr 2004 17:22:10 Z"
6> httpd_util:convert_request_date(DateString).

RFC 1123 (and RFC 822) are used frequently as the basis for exchanging dates and times, particularly in Internet applications.