如何在 Python 中将天转换为小时、分钟和秒 [英] How transform days to hours, minutes and seconds in Python
本文介绍了如何在 Python 中将天转换为小时、分钟和秒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有值 1 day, 14:44:00
我想将其转换为:38:44:00
.
I have value 1 day, 14:44:00
which I would like transform into this: 38:44:00
.
我尝试了以下代码:
myTime = ((myTime.days*24+myTime.hours), myTime.minutes, myTime.seconds)
但它不起作用.我收到此错误消息:
But it doesn't work. I got this error message:
'datetime.timedelta' 对象没有属性 'hours'
'datetime.timedelta' object has no attribute 'hours'
推荐答案
timedelta 对象没有 hours 属性.只有微秒
、秒
和天
.
The timedelta object doesn't have hours property. Only microseconds
, seconds
and days
.
使用:
myTime = '%02d:%02d:%02d.%06d' % (myTime.days*24 + myTime.seconds // 3600, (myTime.seconds % 3600) // 60, myTime.seconds % 60, myTime.microseconds)
这篇关于如何在 Python 中将天转换为小时、分钟和秒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文