Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parsing an ISO datetime in Python [duplicate]

Possible Duplicate:
Converting string to datetime object in python

Given the below Python

import datetime

>>> a
'2011-05-04 16:20:09 -0700'
>>> datetime.datetime.strptime(a, "%Y-%m-%d %H:%M:%S %z")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.6/_strptime.py", line 317, in _strptime
    (bad_directive, format))
ValueError: 'z' is a bad directive in format '%Y-%m-%d %H:%M:%S %z'
>>> 

I don't really understand how %z is a bad directive.

Reference: http://docs.python.org/library/datetime.html#strftime-strptime-behavior

This is from hg, which says that it is in ISO8601 format.

like image 984
Paul Nathan Avatar asked May 05 '11 18:05

Paul Nathan


1 Answers

Here is the complete story:

http://bugs.python.org/issue6641

and related:

Converting string with UTC offset to a datetime object

like image 93
Andreas Jung Avatar answered Sep 22 '22 12:09

Andreas Jung