function formatDate (val, keys = "YYYY-MM-DD hh:mm:ss") {
const date = new Date(val)
const obj = {
'YYYY': date.getFullYear(),
'MM': date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1,
'DD': date.getDate() < 10 ? '0' + date.getDate() : date.getDate(),
'hh': date.getHours() < 10 ? '0' + date.getHours() : date.getHours(),
'mm': date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes(),
'ss': date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
}
for (let key in obj) {
keys = keys.replace(key, obj[key])
}
return keys
}
12-20
4万+
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交