How do I translate a ISO 8601 datetime string into a Python datetime object?

Posted by Andrey Fedorov on Stack Overflow See other posts from Stack Overflow or by Andrey Fedorov
Published on 2009-06-09T10:36:34Z Indexed on 2010/05/17 18:30 UTC
Read the original article Hit count: 203

Filed under:
|

I'm getting a datetime string in a format like "2009-05-28T16:15:00" (this is ISO 8601, I believe) one hack-ish option seems to be to parse the string using time.strptime and passing the first 6 elements of the touple into the datetime constructor, like:

datetime.datetime(*time.strptime("2007-03-04T21:08:12", "%Y-%m-%dT%H:%M:%S")[:6])

I haven't been able to find a "cleaner" way of doing this, is there one?

© Stack Overflow or respective owner

Related posts about python

Related posts about django-templates