我正在尝试以下代码:
time.mktime(datetime.datetime.strptime("2016-10-17 02:35:01+00:00",
"%Y-%m-%d %H:%M:%S %z"))
它返回错误:
ValueError: time data '2016-10-17 02:35:01+00:00' does not match format '%Y-%m-%d %H:%M:%S %z'
答案 0 :(得分:1)
如果您对datetime directives不是很熟悉,我建议您改用dateutil.parser
。例如:
>>> import dateutil.parser
>>> s = '2016-10-17 02:35:01+00:00'
>>> my_date = dateutil.parser.parse(s)
>>> my_date
datetime.datetime(2016, 10, 17, 2, 35, 1, tzinfo=tzutc())