From this post I would try this to avoid leap issues
moment("2015-01-01").startOf('day')
.seconds(s)
.format('H:mm:ss');
I did not run jsPerf, but I would think this is faster than creating new date objects a million times
function pad(num) {
return ("0"+num).slice(-2);
}
function hhmmss(secs) {
var minutes = Math.floor(secs / 60);
secs = secs%60;
var hours = Math.floor(minutes/60)
minutes = minutes%60;
return `${pad(hours)}:${pad(minutes)}:${pad(secs)}`;
// return pad(hours)+":"+pad(minutes)+":"+pad(secs); for old browsers
}
function pad(num) {_x000D_
return ("0"+num).slice(-2);_x000D_
}_x000D_
function hhmmss(secs) {_x000D_
var minutes = Math.floor(secs / 60);_x000D_
secs = secs%60;_x000D_
var hours = Math.floor(minutes/60)_x000D_
minutes = minutes%60;_x000D_
return `${pad(hours)}:${pad(minutes)}:${pad(secs)}`;_x000D_
// return pad(hours)+":"+pad(minutes)+":"+pad(secs); for old browsers_x000D_
}_x000D_
_x000D_
for (var i=60;i<=60*60*5;i++) {_x000D_
document.write(hhmmss(i)+'<br/>');_x000D_
}_x000D_
_x000D_
_x000D_
/* _x000D_
function show(s) {_x000D_
var d = new Date();_x000D_
var d1 = new Date(d.getTime()+s*1000);_x000D_
var hms = hhmmss(s);_x000D_
return (s+"s = "+ hms + " - "+ Math.floor((d1-d)/1000)+"\n"+d.toString().split("GMT")[0]+"\n"+d1.toString().split("GMT")[0]);_x000D_
} _x000D_
*/
_x000D_