// 获取今天的日期
let today = new Date();
// 设置 beginDate 为今天的上午8点
let beginDate = new Date(today.getFullYear(), today.getMonth(), today.getDate(), 8, 0, 0, 0);
// 设置 finishDate 为 beginDate 的后三天的0点
let finishDate = new Date(beginDate.getFullYear(), beginDate.getMonth(), beginDate.getDate() + 3, 0, 0, 0,0);
// 设置 publicityDate 为 finishDate 的后三天的0点
let publicityDate = new Date(finishDate.getFullYear(), finishDate.getMonth(), finishDate.getDate() + 3, 0, 0, 0,0);
beginDate=formatDate(beginDate);
finishDate=formatDate(finishDate);
publicityDate=formatDate(publicityDate);
主要方法:
function formatDate(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 M =date.getMinutes()
M = M < 10 ? ('0' + M) : M
let s =date.getSeconds()
s = s < 10 ? ('0' + s) : s
let dateTime= y + '-' + m + '-' + d + ' ' + h + ':' + M + ':' + s;
return dateTime;
}