js 设置当前时间的后24小时、后一小时等相对时间
let t = new Date().getTime() - 24 * 60 * 60 * 1000;
let d = new Date(t);
let theMonth = d.getMonth() + 1;
let theDate = d.getDate();
let theHours = d.getHours();
let theMinutes = d.getMinutes();
let theSecond = d.getSeconds();
if (theMonth < 10) {
theMonth = '0' + theMonth
}
if (theDate < 10) {
theDate = '0' + theDate
}
if (theHours < 10) {
theHours = '0' + theHours
}
if (theMinutes < 10) {
theMinutes = '0' + theMinutes
}
if (theSecond < 10) {
theSecond = '0' + theSecond
}
let date = d.getFullYear() + '-' + theMonth + '-' + theDate
let time = theHours + ':' + theMinutes + ':' + theSecond
let Spare = date + ' ' + time
console.log(date)
console.log(time)
console.log(Spare)
return Spare
}