RFC 2822 format date printing function in python

George Yoshida ml at dynkin.com
Fri May 6 05:12:25 EDT 2005


praba kar wrote:

 >    In Php we can print RFC 2822 formatted date by
 > date('r') with parameter r.  Then it will print the
 > below format date.
 > "Thu,  7 Apr 2005 01:46:36 -0300".
 > I want to print same RFC 2822 format in python. Is it
 > possible in python? . If possible kindly mention the
 > function related to print RFC format date
 >

Not as simple as PHP, but of course it's possible :-)

 >>> from email.Utils import formatdate
 >>> formatdate(localtime=True)
'Fri, 06 May 2005 18:00:20 +0900'

  http://docs.python.org/lib/module-email.Utils.html

If you want to do the same thing with time module, you need a few
more lines to calcualate the timezone.

quote from footnote:

   Note that the sign of the timezone offset is the opposite of the
   sign of the time.timezone variable for the same timezone; the
   latter variable follows the POSIX standard while this module
   follows RFC 2822.


  http://docs.python.org/lib/module-time.html

-- 
george
http://www.dynkin.com/



More information about the Python-list mailing list