在Python中解析ISO日期时间
可能是重复的问题:
在Python中将字符串转换为日期时间对象
给定下面的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'
>>>
我不太明白为什么%z
这个指令不好用。
参考链接: http://docs.python.org/library/datetime.html#strftime-strptime-behavior
这是来自hg的内容,它说这是ISO8601格式。