snippetpythonCritical
How do I convert seconds to hours, minutes and seconds?
Viewed 0 times
howconverthourssecondsandminutes
Problem
I have a function that returns information in seconds, but I need to store that information in hours:minutes:seconds.
Is there an easy way to convert the seconds to this format in Python?
Is there an easy way to convert the seconds to this format in Python?
Solution
You can use
datetime.timedelta function:>>> import datetime
>>> str(datetime.timedelta(seconds=666))
'0:11:06'Code Snippets
>>> import datetime
>>> str(datetime.timedelta(seconds=666))
'0:11:06'Context
Stack Overflow Q#775049, score: 1264
Revisions (0)
No revisions yet.