datetime模块的有效日期范围是多少? [英] What is the range of valid dates for the datetime module?
问题描述
我正在使用Python datetime
模块。我用它来确定给定日期的星期几。当日期无效时,Python方便地引发 ValueError
;例如,在非ap年2月29日。
I'm playing with the Python datetime
module. I'm using it to determine the day of the week for a given date. Python conveniently raises a ValueError
when the date is invalid; e.g., for February 29 on non-leap years.
我发现,对于大于10,000 AD的年份,在许多非2月的日期中都会引发 ValueError
例外29.这使我认为 datetime
模块对于将来的那个日期无效。
I have found that for years greater than 10,000 AD, ValueError
exceptions are raised for many dates that are not February 29. This leads me to consider that the datetime
module is not valid for dates that far in the future.
datetime
模块的有效日期范围是什么?
What is the range of valid dates for the datetime
module?
推荐答案
>>> from datetime import date
>>> date.min
datetime.date(1, 1, 1)
>>> date.max
datetime.date(9999, 12, 31)
这篇关于datetime模块的有效日期范围是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!