2024-03-29 14:03:37 发布
网友
我正在阅读从csv到python的日期,格式是2017-01-04。我试着像这样处理约会
from datetime import datetime day1 = datetime.strptime(date1, date_format)
我使用date_format = "%y-%m-%d"
date_format = "%y-%m-%d"
然而,当我处理数据时,我得到了一个错误:
time data '2017-01-04' does not match format '%y-%m-%d'
应该是什么?你知道吗
比如:
from datetime import datetime day1 = datetime.utcnow().strptime('2017-01-04', '%Y-%m-%d')
Y - Year with century as a decimal number.y - Year without century as a zero-padded decimal number.
Y - Year with century as a decimal number.
y - Year without century as a zero-padded decimal number.
因此,应该使用上Y
有关格式的更多信息,请参见here
You can run it-This code run successfully and print-2017-01-04 00:00:00
from datetime import datetime day1 = datetime.utcnow().strptime('2017-01-04', '%Y-%m-%d') print(day1)
比如:
因此,应该使用上Y
有关格式的更多信息,请参见here
相关问题 更多 >
编程相关推荐