Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting seconds into HH:MM:SS [duplicate]

Possible Duplicate:
convert seconds to HH-MM-SS with javascript ?

Hi,

I have a float of 16.4534, which is the seconds of a duration of a video. I want to convert this into HH:MM:SS so it would look like 00:00:16.

Have done a search but haven't found anything relavent.

Do I need to use a regex?

Help much appreciated.

Thanks in advance.

like image 795
shahidaltaf Avatar asked Apr 04 '11 13:04

shahidaltaf


People also ask

How do you convert seconds to HH mm SS?

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 seconds to HH mm SS in Python?

strftime('%H:%M:%S', time. gmtime(864001)) return a nasty surprise.


1 Answers

function secondsToHms(d) {      d = Number(d);        var h = Math.floor(d / 3600);      var m = Math.floor(d % 3600 / 60);      var s = Math.floor(d % 3600 % 60);        return ('0' + h).slice(-2) + ":" + ('0' + m).slice(-2) + ":" + ('0' + s).slice(-2);  }    document.writeln('secondsToHms(10) = ' + secondsToHms(10) + '<br>');  document.writeln('secondsToHms(30) = ' + secondsToHms(30) + '<br>');  document.writeln('secondsToHms(60) = ' + secondsToHms(60) + '<br>');  document.writeln('secondsToHms(100) = ' + secondsToHms(100) + '<br>');  document.writeln('secondsToHms(119) = ' + secondsToHms(119) + '<br>');  document.writeln('secondsToHms(500) = ' + secondsToHms(500) + '<br>');
like image 184
Thorben Avatar answered Sep 21 '22 02:09

Thorben