我有约会 - 2015.05.20
使用python计算从今天到此日期剩余天数的最佳方法是什么?
from datetime import *
today = date.today()
future = date(2015,05,20)
???
答案 0 :(得分:17)
diff = future - today
print diff.days
diff
是timedelta个对象。
答案 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