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

TypeScript 复制代码
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

相关推荐
.痞老板.6 小时前
java ee--多线程(进阶)
java·java-ee
treasure1407 小时前
【复古】浅尝Django前后端不分离
前端·css·python·django·bootstrap·html·web
深入云栈8 小时前
Netty 4.2.x 源码深度解析 (二十三):ByteBuf 核心设计 —— 索引、类型与零拷贝
java·后端·架构
唐墨1238 小时前
linux kernel 比较数据大小的宏定义
linux·算法
jay神8 小时前
基于 YOLOv8 的手势识别系统(Web 版)
前端·人工智能·python·深度学习·yolo·计算机视觉·计算机毕业设计
屏什么录8 小时前
长时间录屏中途崩溃:MP4 打不开的 6 种救回方案与参数设置
前端·音视频开发
code_Bo9 小时前
不只命令行:我把跨 Agent 会话同步做成了桌面应用
前端·javascript·后端
拂拉氏9 小时前
【知识讲解-题目讲解】 统计满足K约束的子字符串数量2 (滑动窗口+前缀和+二分查找+分析)
算法·前缀和·二分查找·滑动窗口
kyriewen9 小时前
AI 能把页面写出来,为什么改个需求就开始崩?
前端·javascript·人工智能
wang_shu_mo_ran9 小时前
MyBatis 从入门到进阶(一)
java·spring·mybatis