Skip to content

Instantly share code, notes, and snippets.

@hiyangguo
Created September 6, 2016 09:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hiyangguo/5ba56840a0bcb9947b614cd21cbeb6a5 to your computer and use it in GitHub Desktop.
Save hiyangguo/5ba56840a0bcb9947b614cd21cbeb6a5 to your computer and use it in GitHub Desktop.
秒转HH:mm:ss
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