键错误,时间数据与格式不匹配

问题描述 投票:-1回答:1

我收到以下错误:

time data "2020-03-06" doesn't match the format %Y/%m/%d 

但是我看不出使用当前参数有什么错我正在使用以下代码

tmp = dt.datetime.strptime(date[i], '%Y/%m/%d')
python time helper
1个回答
0
投票

由于错误消息表明格式期望为“%Y /%m /%d”,因此您具有“ 2020-03-06”用反斜杠替换破折号。即>

tmp = dt.datetime.strptime("2020/03/06", '%Y/%m/%d')

应该可以解决该错误。由于看起来日期是作为字符串存储在date [i]中,因此可以执行date[i].replace("-","/")

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.