Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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'

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
271 views
Welcome To Ask or Share your Answers For Others

1 Answer

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)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...