当前位置:网站首页>js 格式化时间
js 格式化时间
2022-04-23 14:09:00 【瑞瑞小同学】
export default function dateFormat(fmt, date) {
// 日期转换
let ret;
const opt = {
"Y+": date.getFullYear().toString(), // 年
"m+": (date.getMonth() + 1).toString(), // 月
"d+": date.getDate().toString(), // 日
"H+": date.getHours().toString(), // 时
"M+": date.getMinutes().toString(), // 分
"S+": date.getSeconds().toString() // 秒
// 有其他格式化字符需求可以继续添加,必须转化成字符串
};
for (let k in opt) {
ret = new RegExp("(" + k + ")").exec(fmt);
if (ret) {
fmt = fmt.replace(ret[1], (ret[1].length == 1) ? (opt[k]) : (opt[k].padStart(ret[1].length, "0")))
};
};
return fmt;
}
调用
DateFormat('YY-mm-dd HH:MM:SS', new Date()),
版权声明
本文为[瑞瑞小同学]所创,转载请带上原文链接,感谢
https://blog.csdn.net/yr123456654321/article/details/109671686
边栏推荐
- FBS (fman build system) packaging
- STD:: map and STD:: vector memory free
- 星界边境Starbound创意工坊订阅的mod的存放路径
- krpano全景之vtour文件夹和tour
- 使用开源调研工具Prophet是一种什么体验?
- mysql查询库大小
- VMware Workstation 无法连接到虚拟机。系统找不到指定的文件
- findstr不是内部或外部命令解决方法
- 快速搞懂线程实现的三种方式
- Research on recyclerview details - Discussion and repair of recyclerview click dislocation
猜你喜欢
随机推荐
星界边境文本自动翻译机(高级版)使用说明
获取线程返回值Future接口与FutureTask类使用介绍
Essential difference between restful WebService and gSOAP webservice
openstack理论知识
MySQL数据库讲解(八)
第四届“传智杯”全国大学生IT技能大赛(决赛B组) 题解
A table splitting implementation scheme of MySQL and InnoDB, MyISAM and MRG_ Introduction to MyISAM and other engine application scenarios
1到100号的灯开关问题
Five ways of using synchronized to remove clouds and fog are introduced
教育行业云迁移最佳实践:海云捷迅使用HyperMotion云迁移产品为北京某大学实施渐进式迁移,成功率100%
線程組ThreadGroup使用介紹+自定義線程工廠類實現ThreadFactory接口
MySQL数据库讲解(十)
Wechat applet initializes Bluetooth, searches nearby Bluetooth devices and connects designated Bluetooth (I)
差分隐私(背景介绍)
HyperBDR云容灾V3.2.1版本发布|支持更多云平台,新增监控告警功能
mysql查询库大小
星界边境Starbound创意工坊订阅的mod的存放路径
贷款市场报价利率(LPR)与贷款基准利率介绍
JDBC和servlet写CRUD的接口总结
使用DialogFragment的一些感受及防踩坑经验(getActivity、getDialog为空,cancelable无效等)









