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.
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.
strftime('%H:%M:%S', time. gmtime(864001)) return a nasty surprise.
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>');
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