从今天到给定日期还有多少天

时间:2011-10-02 17:34:18

标签: python

我有约会 - 2015.05.20

使用python计算从今天到此日期剩余天数的最佳方法是什么?

from datetime import *
today = date.today()
future = date(2015,05,20)
???

2 个答案:

答案 0 :(得分:17)

diff = future - today
print diff.days

difftimedelta个对象。

答案 1 :(得分:3)

减去它们。

>>> from datetime import *
>>> today = date.today()
>>> future = date(2015,05,20)
>>> str(future - today)
'1326 days, 0:00:00'
>>> (future - today).days
1326