有没有办法将日期时间导入的天数转换为整数

问题描述 投票:0回答:1

我对编程和练习相当陌生,我决定制作一个程序来计算你还活着多少天,然后将其转换为你还活着的小时数。但是,我不知道如何将天数转换为整数以阻止它在天数和小时数之后打印“天,0:00:00”。

这是我的代码:

from datetime import date
    
today = date.today()
day = input("Please enter the day you were born on:\n")
month = input("Please enter the month you were born in:\n")
year = input("Please enter the year you were born in:\n")
birthdate = date(int(year), int(month), int(day))
    
days = today - birthdate
hours = days * 24
    
print(days)
print(hours)
python datetime python-datetime
1个回答
0
投票

使用

days = (today - birthdate).days

© www.soinside.com 2019 - 2024. All rights reserved.