当前位置:网站首页>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
边栏推荐
猜你喜欢

About the configuration and use of json5 in nodejs

Operation instructions of star boundary text automatic translator

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

字节面试编程题:最小的K个数

openstack理论知识

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

Logback logger and root

Research on recyclerview details - Discussion and repair of recyclerview click dislocation

进入新公司,运维工程师从下面这几项了解系统的部署

统信UOS卸载php7.2.24,安装php7.4.27 ;卸载再安装为PHP 7.2.34
随机推荐
Date的after时间判断
Homebrew是什么?以及使用
多云数据流转?云上容灾?年前最后的价值内容分享
redis数据库讲解(四)主从复制、哨兵、Cluster群集
Operation instructions of star boundary text automatic translator
差分隐私(背景介绍)
A table splitting implementation scheme of MySQL and InnoDB, MyISAM and MRG_ Introduction to MyISAM and other engine application scenarios
字节面试编程题:最小的K个数
PySide2
剑指offer刷题(1)--面向华为
grep无法重定向到文件的问题
逻辑卷创建与扩容
贷款市场报价利率(LPR)与贷款基准利率介绍
Multiple inheritance virtual base exercises
openstack理论知识
Win10 comes with groove music, which can't play cue and ape files. It's a curvilinear way to save the country. It creates its own aimpack plug-in package, and aimp installs DSP plug-in
Logging module
logback-logger和root
微信小程序轮播图swiper
x509证书cer格式转pem格式