e r l a n g : c o o k b o o k

/ Erlang.TimeRFC1123

This Web


WebHome 
WebChanges 
TOC
NewRecipe 
WebTopicList 
WebStatistics 

All Webs


Chicken
Cookbook
Erlang
Know
Main
Plugins
Sandbox
Scm
TWiki  

Erlang Links


Erlang.org
Erlang Wiki
ErlMan
Erlang Wiki
The Jungerl
Erlang-fr.org
Joe Armstrong
Lambda the Ultimate

Erlang Web Ring


[Prev]: Joe Armstrong's Page
[Next]: Joe Armstrong's Page

Writing and Parsing RFC 1123 Dates and Times

Problem

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

Solution

The Erlang httpd_util module provides a solution:
1> CurrTime = erlang:universaltime().
{{2004,8,28},{8,15,38}}
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().
{{2004,8,28},{1,19,37}}
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).
{{2004,4,28},{17,22,10}}

Discussion

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

References

RFC-822 - Standard for the format of ARPA Internet text messages

RFC-1123 - Requirements for Internet Hosts - Application and Support

Contributors

Based on work by GordonWeakliem.

-- BrentAFulgham - 28 Aug 2004

CookbookForm
TopicType: Recipe
ParentTopic: TimeRecipes
TopicOrder: 050

 
 
Copyright © 2004 by the contributing authors. All material on the Erlang Cookbook web site is the property of the contributing authors.
This material can be redistributed and/or modified under the terms of the GNU Lesser General Public License (LGPL), version 2.1, as published by the Free Software Foundation.
Ideas, requests, problems regarding Schematics Cookbook? Send feedback.
/ You are Main.guest