Quantcast
Channel: JavaScript seconds to time string with format hh:mm:ss - Stack Overflow
Browsing all 49 articles
Browse latest View live
↧

Answer by M Katz for JavaScript seconds to time string with format hh:mm:ss

Here is yet another version, which handles days also:function FormatSecondsAsDurationString( seconds ){ var s = ""; var days = Math.floor( ( seconds / 3600 ) / 24 ); if ( days >= 1 ) { s +=...

View Article


Answer by Serge K. for JavaScript seconds to time string with format hh:mm:ss

I like the first answer.There some optimisations:source data is a Number. additional calculations is not needed.much excess computingResult code:Number.prototype.toHHMMSS = function () { var seconds =...

View Article


Answer by Raj for JavaScript seconds to time string with format hh:mm:ss

To get the time part in the format hh:MM:ss, you can use this regular expression:(This was mentioned above in same post by someone, thanks for that.) var myDate = new...

View Article

Answer by Ninjakannon for JavaScript seconds to time string with format hh:mm:ss

A regular expression can be used to match the time substring in the string returned from the toString() method of the Date object, which is formatted as follows: "Thu Jul 05 2012 02:45:12 GMT+0100 (GMT...

View Article

Answer by jottos for JavaScript seconds to time string with format hh:mm:ss

Variation on a theme. Handles single digit seconds a little differentlyseconds2time(0) -> "0s"seconds2time(59) -> "59s"seconds2time(60) -> "1:00"seconds2time(1000) ->...

View Article


Answer by Jellicle for JavaScript seconds to time string with format hh:mm:ss

I recommend ordinary javascript, using the Date object. (For a shorter solution, using toTimeString, see the second code snippet.)var seconds = 9999;// multiply by 1000 because Date() requires...

View Article

Answer by powtac for JavaScript seconds to time string with format hh:mm:ss

String.prototype.toHHMMSS = function () { var sec_num = parseInt(this, 10); // don't forget the second param var hours = Math.floor(sec_num / 3600); var minutes = Math.floor((sec_num - (hours * 3600))...

View Article

Answer by Ash Burlaczenko for JavaScript seconds to time string with format...

A Google search turned up this result:function secondsToTime(secs){ secs = Math.round(secs); var hours = Math.floor(secs / (60 * 60)); var divisor_for_minutes = secs % (60 * 60); var minutes =...

View Article


JavaScript seconds to time string with format hh:mm:ss

I want to convert a duration of time, i.e., number of seconds to colon-separated time string (hh:mm:ss)I found some useful answers here but they all talk about converting to x hours and x minutes...

View Article

Browsing all 49 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>