timestampToTime(timestamp) {
//时间戳为10位需*1000,时间戳为13位的话不需乘1000
// var date = new Date(timestamp * 1000);
var date = new Date(timestamp);
const Y = date.getFullYear() + '-';
const M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
const D = date.getDate() + ' ';
const h = date.getHours() + ':';
const m = date.getMinutes() + ':';
const s = date.getSeconds();
return Y + M + D + h + m + s;
},
// 使用示例 console.log(this.timestampToTime(1665633749075));
苹果需要变成 '/'的形式才能显示,记得换一下即可:
const Y = date.getFullYear() + '/'
例如:2022/10/13 15:47
const M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '/';