当前位置:网站首页>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
边栏推荐
猜你喜欢
随机推荐
Jmeter设置环境变量支持在任意终端目录输入jmeter直接启动
Thread group ThreadGroup uses introduction + custom thread factory class to implement threadfactory interface
时间复杂度计算举例
线程组ThreadGroup使用介绍+自定义线程工厂类实现ThreadFactory接口
HyperMotion云迁移助力中国联通,青云完成某央企上云项目,加速该集团核心业务系统上云进程
Some experience of using dialogfragment and anti stepping pit experience (getactivity and getdialog are empty, cancelable is invalid, etc.)
mysql查询库大小
About the configuration and use of json5 in nodejs
Algorithem_ReverseLinkedList
Understand the concepts of virtual base class, virtual function and pure virtual function (turn)
STD:: map and STD:: vector memory free
Visio installation error 1:1935 2: {XXXXXXXX
Quickly understand the three ways of thread implementation
findstr不是内部或外部命令解决方法
操作系统常见面试题目:
Visio画拓扑图随记
RecyclerView高级使用(二)-垂直拖拽排序的简单实现
Storage path of mod subscribed by starbound Creative Workshop at Star boundary
OpenStack如何跨版本升级
帆软中使用if else 进行判断-使用标题条件进行判断









