美文网首页
时间格式化

时间格式化

作者: Sasoli | 来源:发表于2018-03-22 16:13 被阅读0次
    function GetSecondTimeFomate(a) {
        if (a<3600){
            let h = (parseInt(a / 3600));
            if (h.toString().length == 1) {
                h = "0" + h;
            }
            let m = (parseInt((a % 3600) / 60));
            if (m.toString().length == 1) {
                m = "0" + m;
            }
            let s = (a - 3600 * h - 60 * m);
            if (s.toString().length == 1) {
                s = "0" + s;
            }
            return (m + ":" + s)
    
        }else {
            let h = (parseInt(a / 3600));
            if (h.toString().length == 1) {
                h = "0" + h;
            }
            let m = (parseInt((a % 3600) / 60));
            if (m.toString().length == 1) {
                m = "0" + m;
            }
            let s = (a - 3600 * h - 60 * m);
            if (s.toString().length == 1) {
                s = "0" + s;
            }
            return (h + ":" + m + ":" + s)
        }
    }
    
    // 格式化播放时间
    export const getSecondTimeFomate = (time, isShowHour = false) => {
      time = Math.ceil(time);
      const h = (parseInt(time / 3600, 10)).toString().padStart(2, '0');
      const m = (parseInt((time % 3600) / 60, 10)).toString().padStart(2, '0');
      const s = (time - 3600 * h - 60 * m).toString().padStart(2, '0');
    
      return isShowHour || time >= 3600 ? (h + ':' + m + ':' + s) : (m + ':' + s);
    };
    

    相关文章

      网友评论

          本文标题:时间格式化

          本文链接:https://www.haomeiwen.com/subject/rpwaqftx.html