当前位置:网站首页>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
边栏推荐
猜你喜欢
RecyclerView高级使用(一)-侧滑删除的简单实现
win10自带Groove音乐不能播放CUE和APE文件的一种曲线救国办法,自己创建aimppack插件包,AIMP安装DSP插件
Installation and use of postman pit
x509证书cer格式转pem格式
Thread group ThreadGroup uses introduction + custom thread factory class to implement threadfactory interface
关于云容灾,你需要知道这些
字节面试编程题:最小的K个数
krpano全景之vtour文件夹和tour
Some experience of using dialogfragment and anti stepping pit experience (getactivity and getdialog are empty, cancelable is invalid, etc.)
uni-app消息推送
随机推荐
使用Executors类快速创建线程池
HyperMotion云迁移助力中国联通,青云完成某央企上云项目,加速该集团核心业务系统上云进程
进入新公司,运维工程师从下面这几项了解系统的部署
RecyclerView高级使用(二)-垂直拖拽排序的简单实现
Postman的安装使用及填坑心得
微信小程序客服接入,实现发送和接收消息
某政务云项目业务系统迁移调研实践
利用json-server在本地创建服务器请求
Thread group ThreadGroup uses introduction + custom thread factory class to implement threadfactory interface
Installation and use of postman pit
Storage path of mod subscribed by starbound Creative Workshop at Star boundary
OpenStack命令操作
贷款市场报价利率(LPR)与贷款基准利率介绍
jsp学习3
获取线程返回值Future接口与FutureTask类使用介绍
Logging module
mysql查询库大小
JSP学习2
倒计时1天~2022云容灾产品线上发布会即将开始
多云数据流转?云上容灾?年前最后的价值内容分享