Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I convert seconds to hours, minutes and seconds?

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?

like image 690
Specto Avatar asked Apr 21 '09 23:04

Specto


People also ask

What is the equation to convert seconds to hours?

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.

How do you convert seconds to HH mm SS format?

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.

How do you convert 7290 seconds into hours minutes and seconds?

7290 seconds= 121.5 minutes/60 minutes =2.025 hours.


1 Answers

You can use datetime.timedelta function:

>>> import datetime >>> str(datetime.timedelta(seconds=666)) '0:11:06' 
like image 51
SilentGhost Avatar answered Oct 13 '22 21:10

SilentGhost