Python DateTime%D会导致问题
我正在尝试处理日期和日期时间
from datetime import date,datetime
d1 = datetime.strptime('2008-03-03','%y-%m-%d') //the %d is colored different!
d2 = datetime(2008, 2 ,3)
print(date.today())
print(d1 - d2)
错误:
time data '2008-03-03' does not match format '%y-%m-%d'
我在做错什么? 文件的名称为test.py。 多数民众赞成在woule文件,我在vscode中使用rightclick运行它
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

发布评论
评论(3)
喵星人汪星人 2025-01-25 13:18:02
问题在于%y ...
%y年没有一个世纪作为零填充的十进制数字。 00,01,...
99%的年度没有世纪作为小数。 0,1,...,99
%y年,将世纪作为十进制数字。 2013,2019等。
我已经在 <="" a="">,使用修复程序:
from datetime import date,datetime
d1 = datetime.strptime('2008-03-03','%Y-%m-%d')
d2 = datetime(2008, 2 ,3)
print(date.today())
print(d1 - d2)
输出:
2022-04-01 29天,0:00:00
[执行带有退出代码0]
鸵鸟症 2025-01-25 13:18:02
It seems like it's an cosmetic problem:
https://github.com/microsoft/vscode/issues/133127
Code works now, no error, but highlighting is still off, even if I use Extension Bisect and deactivate all extensions, or manually deactivate all extensions.
VSCODE 1.66
~没有更多了~
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
您必须写入%y而不是%y,然后代码变为
You must write %Y not %y, Then the code becomes