January 05, 2005
Outputting dates in RFC822 and ISO8601 formats in Python

I'm not feeing terribly inspired at the moment, so it's time for a spot of meme-jumping. You've seen it in Java, you've seen it in Perl; now here it is in Python - Outputting dates in RFC822 and ISO8601 formats in Python.

Odd thing there - when you ask Python for the current (or default) locale, it gives it to you with an underscore, like so: 'en_GB'. But when you set the locale, you need to provide it with a dash - 'en-GB'. I'm sure that there's a good reson for this, even if I'm too stupid to work out what it is.

Posted to Python by Simon Brunning at January 05, 2005 12:29 PM
Comments

Hmm... is it worth suggesting that constants ISO8601_FORMAT = "%Y-%m-%dT%H:%M:%S" and RFC822_FORMAT = "%a, %e %b %Y %H:%M:%S %z" be added to the time module or something like that? I suppose it would be convenient, but then again it's not THAT hard to re-invent this wheel every time it's needed... just takes a few minutes with the proper docs.

Posted by: Michael Chermside on January 5, 2005 05:58 PM

Now *that's* a good idea.

Well, the ISO one, anyway. Producing the RFC format requires fiddling with locales, or so I gather.

Posted by: Simon Brunning on January 6, 2005 08:36 AM

Python is a thing of beauty. :-)

Posted by: Anthony Eden on January 6, 2005 09:35 PM

ISO8601 format is achievable in python using nothing but "%FT%X" %F == %Y-%m-%d, and %X == "%H:%M:%S".

Posted by: Stephen Thorne on July 27, 2005 12:18 AM

In fact there's datetime.isoformat() which is TZ-gnostic as well.

Posted by: Sergey Schetinin on October 8, 2005 03:33 PM

You can have rfc822 format easily with email.Utils.formatdate().
See http://docs.python.org/lib/module-email.Utils.html

Posted by: Konstantin Veretennicov on December 12, 2005 05:38 PM
Post a comment
Name:


Email Address:


URL:



Comments:


Remember info?