**
10位时间戳转换成时间:
**
function conversionTimestamp(timestamp) {
let date = new Date(timestamp * 1000); //时间戳为10位需*1000,时间戳为13位的话不需乘1000
let Year = date.getFullYear() + ‘年’;
let Month = (date.getMonth() < 9 ? ‘0’ + (date.getMonth() + 1) : date.getMonth() + 1) + ‘月’;
function format(time) {
return time < 10?“0” + time:time;
}
let D = format(date.getDate()) + '日 ';
let h = format(date.getHours()) + ‘:’; // 小时
let m = format(date.getMinutes()); // 分钟
let s = format(date.getSeconds()); // 秒
return Year + Month + Date + h + m + s;
}
// 使用方法
let wantTime = conversionTimestamp(传入你的时间戳);
console.log(wantTime) //结果
**
时间转换为10位时间戳:
**
另外的转换:Math.round(new Date(‘2022/03/26 10:59:59’).getTime() / 1000)
结果:1648263599