当前位置:网站首页>JS format time
JS format time
2022-04-23 14:16:00 【Ruirui junior】
export default function dateFormat(fmt, date) {
// Date conversion
let ret;
const opt = {
"Y+": date.getFullYear().toString(), // year
"m+": (date.getMonth() + 1).toString(), // month
"d+": date.getDate().toString(), // Japan
"H+": date.getHours().toString(), // when
"M+": date.getMinutes().toString(), // branch
"S+": date.getSeconds().toString() // second
// If there are other formatting character requirements, you can continue to add , Must be converted to a string
};
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;
}
call
DateFormat('YY-mm-dd HH:MM:SS', new Date()),
版权声明
本文为[Ruirui junior]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231408339383.html
边栏推荐
猜你喜欢

星界边境文本自动翻译机(高级版)使用说明

金融行业云迁移实践 平安金融云整合HyperMotion云迁移解决方案,为金融行业客户提供迁移服务

PySide2

某政务云项目业务系统迁移调研实践

Some experience of using dialogfragment and anti stepping pit experience (getactivity and getdialog are empty, cancelable is invalid, etc.)

在Clion中给主函数传入外部参数

MySQL数据库讲解(八)

剑指offer刷题(2)--面向华为

困扰多年的系统调研问题有自动化采集工具了,还是开源免费的

HyperBDR云容灾V3.2.1版本发布|支持更多云平台,新增监控告警功能
随机推荐
Returns the subscript after array sorting
Introduction to loan market quotation interest rate (LPR) and loan benchmark interest rate
困扰多年的系统调研问题有自动化采集工具了,还是开源免费的
Multiple inheritance virtual base exercises
MySQL数据库讲解(九)
How QT designer adds resource files
VMware15Pro在Deepin系统里面挂载真机电脑硬盘
mysql 5.1升级到5.67
百度笔试2022.4.12+编程题目:简单整数问题
Visio画拓扑图随记
Recyclerview advanced use (II) - simple implementation of vertical drag and drop sorting
星界边境Starbound创意工坊订阅的mod的存放路径
OpenStack如何跨版本升级
字节面试编程题:最小的K个数
PySide2
HyperBDR云容灾V3.2.1版本发布|支持更多云平台,新增监控告警功能
redis数据库讲解(三)redis数据类型
翻牌效果
dp-[NOIP2000]方格取数
sar命令详解