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?
There are 3,600 seconds in 1 hour. The easiest way to convert seconds to hours is to divide the number of seconds by 3,600.
To do the conversion yourself follow these steps. Find the number of whole hours by dividing the number of seconds by 3,600. The number to the left of the decimal point is the number of whole hours. The number to the right of the decimal point is the number of partial hours.
7290 seconds= 121.5 minutes/60 minutes =2.025 hours.
You can use datetime.timedelta
function:
>>> import datetime >>> str(datetime.timedelta(seconds=666)) '0:11:06'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With