将毫秒数量转换为时分秒字符串(毫秒数→转换为→00:00:00.000形式)

let toHourMinuteSecondByMillisecond = (millisecond, cfg = {}) => {
    let t = "",
        ms = Math.round(millisecond),
        s = Math.floor(ms / 1000),
        d = cfg.isDoubleDigits,//显示双位数
        f = cfg.isFourDigits,//显示4位数
        hz = cfg.hideZero,//隐藏为0的时间单位
        hh = cfg.hideHour,//隐藏小时
        hm = cfg.hideMinute,//隐藏分钟
        hs = cfg.hideSecond,//隐藏秒钟
        hms = cfg.hideMilliSecond;//隐藏毫秒钟
    let hour = Math.floor(s / 3600),
        min = Math.floor(s / 60) % 60,
        sec = s % 60,
        msec = ms % 1000;
    hh || (hz && !hour) || (d && hour < 10 && (t += "0"), t += hour + ":");
    hm || (hz && !min) || (d && min < 10 && (t += "0"), t += min + ":");
    hs || (hz && !sec) || (d && sec < 10 && (t += "0"), t += sec);
    hms || (hz && !msec) || (f && msec < 1000 && (msec = msec.toString().padStart(3, "0")), t += "." + msec);
    return t;
}

延伸阅读解决全网90%以上的日期格式转换、日期序列等骚操作问题-CSDN博客文章浏览阅读5.2k次。function getYearMonthList(startDate, endDate) {//返回月份的数组 如 ['2021/07','2021/08'] var arr = []; var s = new Date(startDate).toLocaleString("zh-Hans-CN", {year: "numeric", month: "2-digit", day: "2-digit"}).split("/"); var e = new Date(endDate)..https://blog.csdn.net/qq_37860634/article/details/118587492

猜你喜欢

转载自blog.csdn.net/qq_37860634/article/details/135087857