JavaScript 把秒转换成分钟,比如100s转换成 01:40

Eaxmple

console.log(minSecond(3462));//57:42
console.log(minSecond(321));//05:21
console.log(minSecond(100));//01:40
console.log(minSecond(8562));//142:42

my answer

function minSecond(n) {
  var second_ = Math.floor(n%60);
  if (second_ < 10) {
    second_ = '0'+ second_;
  }
  if (Math.floor(n / 60) < 10) {
  var a = "0" + Math.floor(n / 60) + ':' + second_;   
  } else {
  var a = Math.floor(n / 60) + ':' + second_;   
  }
  return a; 
}
posted @ 2017-09-17 22:28  芒果夏夏  阅读(363)  评论(0编辑  收藏  举报