getting date into rfc822 format

Peter Hansen peter at engcorp.com
Sun Jul 21 01:19:40 EDT 2002


"Jon J. Morin" wrote:
> 
> date = time.ctime(time.time())
> 
> Which gives me a date like this:
> Sat Jul 20 00:02:03 2002
> 
> When what I want is something like this:
> Fri, 01 Mar 2002 00:18:17 -0500 (EST)
> 
> Incidentally, I have read the rfc822 and I can't figure out what the -0500
> is in the date/time.  Can anyone explain this to me?

See http://www.python.org/doc/current/lib/module-time.html and
search for "RFC 2822" or look at the strftime() formatting codes.

The -0500 is a representation of the time difference between your local time 
and UTC.  In this case it means your time is 5 hours behind UTC.  For
email you should be able to put the time in UTC, so use time.gmtime()
as shown in the example in the docs.

-Peter



More information about the Python-list mailing list