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?
Here is yet another version, which handles days also:
You can manage to do this without any external JS library with the help of JS Date method like following:
There's a new method for strings on the block: padStart
Here is a sample use case: YouTube durations in 4 lines of JavaScript
You can use Momement.js with moment-duration-format plugin:
See also this Fiddle
I'd upvote artem's answer, but I am a new poster. I did expand on his solution, though not what the OP asked for as follows
To get
04Oct 16:31:28 PDT
This works for me...
But if you are starting with just a time quantity, I use two functions; one to format and pad, and one to calculate:
Examples