Skip to content

Instantly share code, notes, and snippets.

@vladislav805
Created December 3, 2016 20:24
Show Gist options
  • Save vladislav805/231767339c81c52879b3b4f5d7278c90 to your computer and use it in GitHub Desktop.
Save vladislav805/231767339c81c52879b3b4f5d7278c90 to your computer and use it in GitHub Desktop.
Duration in seconds to "h:mm:ss" format
Number.prototype.toTimeFormat = function() {
var d = [Math.floor(this / 60 % 60), Math.floor(this % 60)],
h = Math.floor(this / 60 / 60 % 60);
d = d.map(function(n) {return n >= 10 ? n : "0" + n});
h && d.unshift(h);
return d.join(":");
};
// using
var duration = 12345;
console.log(duration.toTimeFormat());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment