1.0.1 • Published 3 years ago
wangyukun-test1 v1.0.1
步骤流程
1.完成功能
2.写一个函数
3.将步骤1放入步骤2中
4.微调(函数封装起来)
function dateformat(str){ const g = new Date(); const format = { Y:g.getFullYear(), M:g.getMonth() + 1, D:g.getDay(), H:g.getHours(), M:g.getMinutes(), S:g.getSeconds(), }; for(let key in format){ str=str.replaceAll(key,formatkey); } return str; }
下载
npm i wangyukun-test1
字母代表意思
Y:年 M:月 D:日 H:时 M:分 S:秒
打印格式
const showDate = require('wangyukun-test1') console.log(Date.format('Y/M/D/H/M/S')) console.log(Date.format('Y-M-D-H-M-S')) console.log(Date.format('Y-M-D H:M:S')) console.log(Date.format('Y-M-D')) console.log(Date.format('H:M:S'))