Created
December 3, 2016 20:24
-
-
Save vladislav805/231767339c81c52879b3b4f5d7278c90 to your computer and use it in GitHub Desktop.
Duration in seconds to "h:mm:ss" format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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