在Python中解析ISO日期时间

Pau*_*han 10 python datetime

可能重复:
在python中将字符串转换为datetime对象

鉴于以下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'
>>> 
Run Code Online (Sandbox Code Playgroud)

我真的不明白%z一个坏指令怎么样.

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

这是来自hg,它说它是ISO8601格式.