[英]datetime.strptime() conversion failure for year 10000
The below python code worked fine until 12-31-9999.下面的 python 代码工作正常,直到 12-31-9999。
It threw error once I changed the date to 01-01-10000 (see the screen shot attached)一旦我将日期更改为 01-01-10000,它就会抛出错误(见附上的屏幕截图)
from datetime import datetime
import time
myNewDate = "12-31-9999"
myNewDateTime = datetime.strptime(myNewDate, '%m-%d-%Y').date()
print (myNewDateTime)
Here is the screen shot:这是屏幕截图:
%Y
signifies a 4 digit year, the last 0 is unmatched by the pattern. %Y
表示 4 位数字年份,最后一个 0 与模式不匹配。 You can't use python datetime to work with years beyond 9999: https://docs.python.org/3/library/datetime.html#datetime.MAXYEAR您不能使用 python datetime 来处理超过 9999 年的年份: https : //docs.python.org/3/library/datetime.html#datetime.MAXYEAR
The below python code worked fine until 12-31-9999.下面的 python 代码工作正常,直到 12-31-9999。
It threw error once I changed the date to 01-01-10000 (see the screen shot attached)一旦我将日期更改为 01-01-10000,它就会抛出错误(见附上的屏幕截图)
from datetime import datetime
import time
myNewDate = "12-31-9999"
myNewDateTime = datetime.strptime(myNewDate, '%m-%d-%Y').date()
print (myNewDateTime)
Here is the screen shot:这是屏幕截图:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.