当前位置:网站首页>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
边栏推荐
- 统信UOS PHP7.2.3升级至PHP7.2.24
- 关于NodeJS中JSON5的相关配置和使用
- dp-[NOIP2000]方格取数
- On the multi-level certificate based on OpenSSL, the issuance and management of multi-level Ca, and two-way authentication
- 帆软中单元格中隔行变色以及数量大于100字体变大变红设置
- Some experience of using dialogfragment and anti stepping pit experience (getactivity and getdialog are empty, cancelable is invalid, etc.)
- mysql 5.1升级到5.69
- 贷款市场报价利率(LPR)与贷款基准利率介绍
- mysql 5.1升级到5.67
- Request module
猜你喜欢
利用json-server在本地创建服务器请求
云迁移的六大场景
OpenStack命令操作
ThreadGroup ThreadGroup implémente l'interface threadfactory en utilisant la classe Introduction + Custom thread Factory
Installation and use of postman pit
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
Thread group ThreadGroup uses introduction + custom thread factory class to implement threadfactory interface
MySQL数据库讲解(七)
Logback logger and root
帆软中根据分类进行汇总
随机推荐
dp-能量项链
Get the thread return value. Introduction to the use of future interface and futuretask class
ThreadGroup ThreadGroup implémente l'interface threadfactory en utilisant la classe Introduction + Custom thread Factory
数据库DbVisualizer Pro报文件错误,导致数据连接失败
Jira截取全图
RecyclerView进阶使用-实现仿支付宝菜单编辑页面拖拽功能
RecyclerView细节研究-RecyclerView点击错位问题的探讨与修复
文字组合,不重复,做搜索或查询关键字匹配
A table splitting implementation scheme of MySQL and InnoDB, MyISAM and MRG_ Introduction to MyISAM and other engine application scenarios
RecyclerView高级使用(二)-垂直拖拽排序的简单实现
某政务云项目业务系统迁移调研实践
帆软中单元格中隔行变色以及数量大于100字体变大变红设置
回顾2021:如何帮助客户扫清上云最后一公里的障碍?
Mysql的安装过程(已经安装成功的步骤说明)
Homebrew是什么?以及使用
帆软中根据分类进行汇总
Oracle-数据泵使用
MySQL基础知识
Wechat applet communicates with low-power Bluetooth - receives data sent by hardware (IV)
mysql 5.1升级到5.69