我有以下代码打印天数为“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()
答案 0 :(得分:3)
要从timedelta
对象获取整天天数,只需引用days
数据:
print 'Days: {}'.format(days.days)
Days: 8
答案 1 :(得分:0)
print "DAYS: " + str(days.days)
DAYS: 8