简体   繁体   中英

How transform days to hours, minutes and seconds in Python

I have value 1 day, 14:44:00 which I would like transform into this: 38:44:00 .

I've tried the following code:

myTime = ((myTime.days*24+myTime.hours), myTime.minutes, myTime.seconds)

But it doesn't work. I got this error message:

'datetime.timedelta' object has no attribute 'hours'

The timedelta object doesn't have hours property. Only microseconds , seconds and days .

Use:

myTime = '%02d:%02d:%02d.%06d' % (myTime.days*24 + myTime.seconds // 3600, (myTime.seconds % 3600) // 60, myTime.seconds % 60, myTime.microseconds)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM