我试图将天数(用户输入)减去datetime。我一直在尝试理解如何将“days”转换为timedelta类型,但没有成功,请参阅下面的代码:使用我目前所拥有的。你知道吗
from datetime import datetime, timedelta
expiry_input = input("Input Expiry Date: YYYY-MM-DD: ")
input_object = datetime.strptime(expiry_input, '%Y-%m-%d')
notice_non_renewal = input("Input Notice of Non-Renewal: ")
non_renewal_object = datetime.strptime(notice_non_renewal, '%d')
notice_day = input_object - non_renewal_object
print(notice_day)
结果如下:
Input Expiry Date: YYYY-MM-DD: 2017-05-30
Input Notice of Non-Renewal: 30
42854 days, 0:00:00
最终结果应为2017-05-01
构建
timedelta
对象:相关问题 更多 >
编程相关推荐