python time + timedelta 等价物 [英] python time + timedelta equivalent
本文介绍了python time + timedelta 等价物的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试做这样的事情:
I'm trying to do something like this:
time() + timedelta(hours=1)
但是,Python 不允许,显然是有充分理由的.
however, Python doesn't allow it, apparently for good reason.
有人有简单的解决方法吗?
Does anyone have a simple work around?
推荐答案
解决方案在您提供的链接中 在您的问题中:
The solution is in the link that you provided in your question:
datetime.combine(date.today(), time()) + timedelta(hours=1)
完整示例:
from datetime import date, datetime, time, timedelta
dt = datetime.combine(date.today(), time(23, 55)) + timedelta(minutes=30)
print dt.time()
输出:
00:25:00
这篇关于python time + timedelta 等价物的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文