首页 > Web开发 > 详细

js将秒转化为时分秒

时间:2020-01-08 11:34:17      阅读:130      评论:0      收藏:0      [点我收藏+]
formatSeconds(value) {
    let result = parseInt(value)
    let h = Math.floor(result / 3600) < 10 ? ‘0‘ + Math.floor(result / 3600) : Math.floor(result / 3600);
    let m = Math.floor((result / 60 % 60)) < 10 ? ‘0‘ + Math.floor((result / 60 % 60)) : Math.floor((result / 60 % 60));
    let s = Math.floor((result % 60)) < 10 ? ‘0‘ + Math.floor((result % 60)) : Math.floor((result % 60));

    let res = ‘‘;
    if(h !== ‘00‘) res += `${h}h`;
    if(m !== ‘00‘) res += `${m}min`;
    res += `${s}s`;
    return res;
  }

  90s  => 1min30s

js将秒转化为时分秒

原文:https://www.cnblogs.com/sameen/p/12165614.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!