1
我想在python中创建一个程序,告诉你你曾经度过多少日子。我目前的代码是:Python生命的长度
import datetime
from datetime import timedelta
year = int(input('Enter the year'))
month = int(input('Enter the month'))
day = int(input('Enter the day'))
date1 = datetime.date(year, month, day)
now = datetime.datetime.now().date()
days = now - date1
print days
目前它打印数量的天数,然后0:00:00
。例如:5914 days, 0:00:00
。有谁知道如何摆脱0:00:00
?
所以你只是想'(现在 - 日期1).days'?计算结果是['timedelta'](https://docs.python.org/2/library/datetime.html#datetime.timedelta)对象。 – jonrsharpe
'>>> print'days:{}'。format(days.days)' – Kasramvd
通过阅读这个[doc](https://docs.python.org/2/library/datetime.html)将大大帮助 – taesu