当前位置: 首页 > news >正文

js时间格式化精确到毫秒

/*** 数字前置补零* @param value 值* @param length 位数* @returns {string}*/
export function digit(value, length = 2) {if (typeof value === "undefined" ||value === null ||String(value).length >= length) {return value;}return (Array(length).join("0") + value).slice(-length);
}//格式化日期到毫秒
export function toDateString(time, format = "yyyy-MM-dd HH:mm:ss") {if (!time) {return "";}if (typeof time === "number" && String(time).length === 10) {time = time * 1000; // 10位时间戳处理}const date = new Date(time);const ymd = [digit(date.getFullYear(), 4),digit(date.getMonth() + 1),digit(date.getDate()),];const hms = [digit(date.getHours()),digit(date.getMinutes()),digit(date.getSeconds()),digit(date.getMilliseconds()),];return format.replace(/yyyy/g, ymd[0]).replace(/MM/g, ymd[1]).replace(/dd/g, ymd[2]).replace(/HH/g, hms[0]).replace(/mm/g, hms[1]).replace(/ss/g, hms[2]).replace(/SSS/g, hms[3]);
}

http://www.lryc.cn/news/58438.html

相关文章:

  • QT样式表详解
  • 最值得入手的好物有哪些,推荐几款实用的数码好物
  • 【20230407】NVIDIA显卡算力、Jetson比较
  • dsl语法
  • 不让CPU偷懒
  • 动力节点王鹤SpringBoot3笔记——第七章 视图技术Thymeleaf
  • 从比特保存和信息保存看数字资源长期保存
  • 兰伯特光照模型(Lambert Lighting)和半兰伯特光照模型(Half-Lanbert)
  • Python 进阶指南(编程轻松进阶):二、环境配置和命令行
  • 求职半年,三月成功拿到阿里offer,分享一波面经...
  • 餐饮店的运营需要考虑哪些方面
  • Multi-modal Alignment using Representation Codebook
  • 关于vector的emplace_back和push_back的区别
  • Vue——表单输入绑定
  • MySQL性能优化(二)索引
  • < 每日闲谈:你真的了解 “ ChatGPT ” 嘛 ? >
  • 改善Instagram客户服务的6个技巧
  • 8年经验之谈:4步解决测试与开发人员有争议的bug问题...
  • Linux日常小技巧shell脚本
  • 技术创业者必读:从验证想法到技术产品商业化的全方位解析
  • Docker Registry 本地镜像发布到私有库
  • Pytorch构建ResNet-50V2
  • 【01】PointNet论文解析
  • nuxt.js 在IE浏览器||其他浏览不识别document/window 情况处理
  • JavaEE简单示例——基于注解的SSM整合
  • EFBG-06-250双比例阀放大器
  • 初级算法-栈与队列
  • 菜鸟教程之Android学习笔记Service
  • 半个月狂飙1000亿,ChatGPT概念股凭什么?
  • linux使用systemctl