How to convert seconds to hours, minutes and seconds in Python

1 Answer

0 votes
from datetime import datetime

def get_duration(duration):
    hours = int(duration / 3600)
    minutes = int(duration % 3600 / 60)
    seconds = int((duration % 3600) % 60)
    return '{:02d}:{:02d}:{:02d}'.format(hours, minutes, seconds)

print(get_duration(3671))

   
   
   
'''
run:
   
01:01:11
   
'''

 



answered Mar 2, 2022 by avibootz
...