dengjie commit : 发布日期格式解决

This commit is contained in:
clay
2022-12-26 22:19:45 +08:00
parent d3c83c4c7d
commit ff682aedc3
3 changed files with 25 additions and 3 deletions

16
utills/date.js Normal file
View File

@@ -0,0 +1,16 @@
function dateFormat(time) {
let date = new Date(time);
let year = date.getFullYear();
// 在日期格式中月份是从0开始的因此要加0使用三元表达式在小于10的前面加0以达到格式统一 如 09:11:05
let month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
let day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
let hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
let minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
let seconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
// 拼接
return year + "-" + month + "-" + day + " " + hours + ":" + minutes;
// return year + "-" + month + "-" + day;
}
module.exports = {
dateFormat
}