/**
* fmt : YYYY-MM-DD 年月日
* fmt : '' 年月日十分秒
*/
function dateFormat(fmt = 'YYYY-MM-DD',dateTime){
let date = new Date()
dateTime ? date = new Date(dateTime) : ''
const option = {
Y: date.getFullYear(), // 年
M: date.getMonth()+1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth(), // 月
D: date.getDate() < 10 ? '0' + date.getDate() : date.getDate(), // 日
h: date.getHours() < 10 ? '0' + date.getHours() : date.getHours(), // 时
m: date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes(), // 分
s: date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds() // 秒
};
if(fmt === 'YYYY-MM-DD'){
return `${option.Y}-${option.M}-${option.D}`
}else{
return `${option.Y}-${option.M}-${option.D} ${option.h}:${option.m}:${option.s}`
}
}
拿走 不谢 !!!