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 format.
So is there a tiny snippet that does this in jQuery or just raw JavaScript?
result:
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.)
A Google search turned up this result:
Here is my vision of solution. You can try my snippet below.
You can use the following function to convert time (in seconds) to
HH:MM:SS
format :Without passing a separator, it uses
:
as the (default) separator :If you want to use
-
as a separator, just pass it as the second parameter:Demo
See also this Fiddle.