0

我有以下代码将天数打印为“8 天,0:00:00”,我只想打印数字,输出应该只有“8”,任何人都可以提供有关如何执行此操作的输入吗?

from datetime import datetime, date

def main ():
    cr_date = '2013-11-01'
    curr_date = '2013-11-09 18:17:53.196126'
    crdate = date(*map(int, cr_date.split("-")))
    currdate = datetime.strptime(curr_date, "%Y-%m-%d %H:%M:%S.%f")
    days = currdate.date() - crdate
    print "DAYS: " + str(days)

if __name__ == '__main__':
    main()
4

2 回答 2

3

要获取timedelta对象的完整天数,只需引用days数据:

print 'Days: {}'.format(days.days)
Days: 8
于 2013-11-10T05:47:49.257 回答
0
print "DAYS: " + str(days.days)
DAYS: 8
于 2013-11-10T05:50:32.453 回答