1、时间戳转日期时间
function timestampToDate(timestamp,index) {
var date = new Date(timestamp + index * 86400000);
var Y = date.getFullYear() + '-';
var M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
var D = date.getDate() + ' ';
var h = date.getHours() + ':';
var m = date.getMinutes() + ':';
var s = date.getSeconds();
return Y+M+D+h+m+s;
}
console.log('后面时间',timestampToTime(new Date().getTime(),2)); //(2022-08-18 09:00:00 , 2) ==> 2022-08-20 09:00:00
2、日期时间转为时间戳,换成分成几天
var date1 = new Date().getTime(); //1660784768348
var date2 = new Date('2022-08-22 00:00:00').getTime(); //1661097600000
const date3 = Math.ceil((date2- date1) / 86400000); //4