Use "duration" of Moment.js to make it easy!
var duration = moment.duration(parseInt(duration, 10));
var addZero = function(v) { return (v<10 ? '0' : '') + Math.floor(v); };
var time = addZero(duration.hours()) +
':' + addZero(duration.minutes()) +
':' + addZero(duration.seconds()) +
':' + addZero(duration.milliseconds());