I have hours in this format,
72.345, 72.629, 71.327, ...
as a result of performing a calculation in Python. It seems that the simplest way to convert these into HH:MM:SS format is using the datetime module like this:
time = str(datetime.timedelta(seconds = 72.345*3600))
However, that returns a values with days, which I don't want:
'3 days, 0:20:42'
This is the best way my brain came up with the final values I want:
str(int(math.floor(time))) + ':' + str(int((time%(math.floor(time)))*60)) + ':' + str(int(((time%(math.floor(time)))*60) % math.floor(((time%(math.floor(time)))*60))*60))
Which is ridiculously long and probably unnecessary. But it does give me the answer I want:
'72:20:41'
Are there better methods?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…