我应该如何解决这个问题?
错误是:
ValueError: time data '2016-10-20 03:43:11+00:00' does not match format '%Y-%m-%d %H:%M:%S%z'
代码是:
fmt = "%Y-%m-%d %H:%M:%S%z"
dt = datetime.strptime(row['Time'], fmt)
一些搜索会给你一些不错的解决方案。
第一个选项:
from datetime import datetime as dt
t = '2016-10-20 03:43:11+00:00'
fmt = "%Y-%m-%d %H:%M:%S+00:00"
d = dt.strptime(t, fmt)
# output datetime.datetime(2016,10,20,3,43,11)
第二种选择:
from dateutil import parser as psr
t = '2016-10-20 03:43:11+00:00'
d = psr.parse(t)
# output datetime.datetime(2016,10,20,3,43,11, tzinfo=tzutc())