如何在 Python 中获取 timedelta 的总小时数和分钟数 [英] How to get total hours and minutes for timedelta in Python
本文介绍了如何在 Python 中获取 timedelta 的总小时数和分钟数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将大于 24 小时的 timedelta 返回或转换为包含总小时数和分钟数(例如,26:30)而不是1 天,2:30"的对象?
解决方案
您可以使用 total_seconds()
来计算秒数.然后可以将其转换为分钟或小时:
How do I return or turn a timedelta, which is bigger than 24 hours, into an object containing the total hours and minutes (for example, 26:30) instead of "1 day, 2:30"?
解决方案
You can use total_seconds()
to compute the number of seconds. This can then be turned into minutes or hours:
>>> datetime.timedelta(days=3).total_seconds()
259200.0
这篇关于如何在 Python 中获取 timedelta 的总小时数和分钟数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文