欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

js时间毫秒转换为字符串时分秒

程序员文章站 2024-01-28 09:17:04
...
convertTimeFormat(timems) {
    let str = '';
    const time = parseInt(timems);
    const hour = Math.floor(time / 3600);
    const hourFormat = hour > 9 ? hour : ('0' + hour);
    const minute = Math.floor((time - hour * 3600) / 60);
    const minuteFormat = minute > 9 ? minute : ('0' + minute);
    const second = Math.floor((time - hour * 3600) - minute * 60);
    const secondFormat = second > 9 ? second : ('0' + second);
    str += hourFormat + ":" + minuteFormat + ":" + secondFormat;
    return str;
  }
相关标签: js时间