控制台打印如下
let time = +new Date() //获取当前时间戳
export function getFamtterTimer(time) { //传入时间
let date = new Date(time),
Y = date.getFullYear(), // 年
M = date.getMonth() + 1, //月
D = date.getDate(), //日
h = date.getHours(), //小时
m = date.getMinutes(), //分钟
s = date.getSeconds(); //秒数
let timer = Y+ '-' + getZero(M) + '-' + getZero(D) + ' ' + getZero(h) + ':' + getZero(m) + ':' + getZero(s);
return timer;
}
export function getZero(num) { // 个位数前补0
if (parseInt(num) < 10) {
num = '0' + num;
}
return num;
}