如何将秒转换为小时、分钟和秒? [英] How do I convert seconds to hours, minutes and seconds?
本文介绍了如何将秒转换为小时、分钟和秒?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个以秒为单位返回信息的函数,但我需要以小时:分钟:秒为单位存储该信息.
是否有一种简单的方法可以在 Python 中将秒数转换为这种格式?
解决方案
您可以使用 datetime.timedelta
函数:
I have a function that returns information in seconds, but I need to store that information in hours:minutes:seconds.
Is there an easy way to convert the seconds to this format in Python?
解决方案
You can use datetime.timedelta
function:
>>> import datetime
>>> str(datetime.timedelta(seconds=666))
'0:11:06'
这篇关于如何将秒转换为小时、分钟和秒?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文