(注意:下面的date可以加个判断是10位时间戳还是13位时间戳来进行编码是否需要*1000; param为你要转换的时间戳变量
if(param.length == 10){
let date = new Date(parseInt(param) * 1000);
}else if(param.length == 13){
let date = new Date(parseInt(param));
}
)
let date = new Date(parseInt(res.data.rows[i].time) * 1000);
let y = date.getFullYear();
let m = date.getMonth() + 1;
m = m < 10 ? ('0' + m) : m;
let d = date.getDate();
d = d < 10 ? ('0' + d) : d;
let h = date.getHours();
h = h < 10 ? ('0' + h) : h;
let minute = date.getMinutes();
let second = date.getSeconds();
minute = minute < 10 ? ('0' + minute) : minute; second = second < 10 ? ('0' + second) : second;
// console.log( y + '-' + m + '-' + d + ' ' + ' ' + h + ':' + minute + ':' + second)
let dates = y + '-' + m + '-' + d + ' ' + ' ' + h + ':' + minute + ':' + second;// 封装的时间戳转换日期函数
dateTrans(date) {
let _date = new Date(parseInt(date));
let y = _date.getFullYear();
let m = _date.getMonth() + 1;
m = m < 10 ? ('0' + m) : m;
let d = _date.getDate();
d = d < 10 ? ('0' + d) : d;
let h = _date.getHours();
h = h < 10 ? ('0' + h) : h;
let minute = _date.getMinutes();
let second = _date.getSeconds();
minute = minute < 10 ? ('0' + minute) : minute; second = second < 10 ? ('0' + second) : second;
// console.log( y + '-' + m + '-' + d + ' ' + ' ' + h + ':' + minute + ':' + second)
let dates = y + '-' + m + '-' + d;
return dates;
},