简体   繁体   English

10000 年的 datetime.strptime() 转换失败

[英]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:这是屏幕截图:

在此处输入图片说明

According to the docs , only 4 digit years are supported.根据docs ,仅支持 4 位数年份。

The years are limited by the 1989 C standard.年份受 1989 C 标准的限制。

%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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM