更新时间:2022-01-23 23:15:03
如果您有两个日期对象,您可以减去它们,从而计算出 timedelta
对象。
If you have two date objects, you can just subtract them, which computes a timedelta
object.
from datetime import date
d0 = date(2008, 8, 18)
d1 = date(2008, 9, 26)
delta = d1 - d0
print(delta.days)
文档的相关部分:
https://docs.python.org/library/datetime.html 。
请参见此答案作为另一个示例。
See this answer for another example.