Created
September 6, 2016 09:33
-
-
Save hiyangguo/5ba56840a0bcb9947b614cd21cbeb6a5 to your computer and use it in GitHub Desktop.
秒转HH:mm:ss
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
function getTime(second) { | |
var s = second % 60; | |
var m = Math.floor(second / 60); | |
var h = m < 60 ? 0 : Math.floor(m / 60); | |
m = m >= 60 ? Math.floor(m % 60) : m; | |
var format = function(num) { | |
return num > 9 ? num : '0' + num; | |
}; | |
return [h, m, s].map(function(t) { | |
return format(t) | |
}).join(':'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment