使用json日期检查到期日期时出现问题

时间:2019-07-14 02:31:28

标签: python

使用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'

1 个答案:

答案 0 :(得分:1)

您的问题位于Wrong 2nd argument type. Found: 'boolean', required: 结尾。在您的格式字符串中,它匹配到+00:00。您必须更改格式字符串以包含.%f,或者您要使用+而不是.00