[Python-ideas] Parsing ISO 8601 with the standard library

Chris Rebert pyideas at rebertia.com
Tue Mar 11 20:28:48 CET 2014


On Tue, Mar 11, 2014 at 11:46 AM, Tin Tvrtković <tinchester at gmail.com> wrote:
> Hello,
>
> it occured to me today that it's not currently possible to parse ISO 8601
> dates using the datetime.datetime.strftime function (I was parsing datetimes
> generated by Postgres). The problem is in the semicolon in the time zone
> offset.
>
> '1997-07-16T19:20:30.45+01:00' is a valid ISO 8601 date and time
> representation, the likes of which can be generated by the datetime module
> itself (the isoformat method). The %z strftime directive only recognizes
> offsets without the semicolon. The Python docs also direct users to inspect
> the platform strftime documentation; on my system the man page clearly
> states %z is "... The +hhmm or -hhmm numeric timezone", again, no semicolon
> support.
>
> Googling around, most common suggestions are to use a third party library
> (such as dateutil), so either this functionality really doesn't exist in a
> simple form in the datetime module, or is really undiscoverable. It seems to
> me ISO 8601 is significant enough (since there are even special methods for
> it in the datetime module) for it to be parsable, in a non-complex way, by
> the standard library.

There's already an open bug about this (well, technically RFC 3339,
but close enough):
http://bugs.python.org/issue15873

Cheers,
Chris


More information about the Python-ideas mailing list