使用json日期检查过期日期时出现问题
我哪里出错了
from datetime import datetime, date
datet = '2019-06-12T00:00:00+00:00'
ExpirationDate = datetime.strptime(datet, "%Y-%m-%dT%H:%M:%S.%f")
now = datetime.now()
if ExpirationDate >= now:
print("ok")
Traceback (most recent call last): File "main.py", line 4, in <module>
ExpirationDate = datetime.strptime(datet, "%Y-%m-%dT%H:%M:%S.%f") File "/usr/local/lib/python3.6/_strptime.py", line 565, in
_strptime_datetime
tt, fraction = _strptime(data_string, format) File "/usr/local/lib/python3.6/_strptime.py", line 362, in _strptime
(data_string, format)) ValueError: time data '2019-06-12T00:00:00+00:00' does not matchformat '%Y-%m-%dT%H:%M:%S.%f'
你的问题在最后的
+00:00
。在格式字符串中,它匹配到.%f
。您必须将格式字符串更改为包含+
,或者将日期改为.00
,而不是+00:00
相关问题 更多 >
编程相关推荐