/**
* 获取选择当前的第几周,当前的周一、周日
* time 选择日期的时间戳
*/
function getNowDateAndNowWeek() {
// 获取当前时间戳
var timestamp = new Date().getTime();
var serverDate = new Date(timestamp);
// 本周周日的时间
var sundayTiem = timestamp + ((7 - serverDate.getDay()) * 24 * 60 * 60 * 1000)
var SundayData = new Date(sundayTiem);
// 年
var tomorrowY = SundayData.getFullYear();
// 月
var tomorrowM = (SundayData.getMonth() + 1 < 10 ? '0' + (SundayData.getMonth() + 1) : SundayData.getMonth() + 1);
// 日
var tomorrowD = SundayData.getDate() < 10 ? '0' + SundayData.getDate() : SundayData.getDate();
console.log('周日: ' + tomorrowY + '-' + tomorrowM + '-' + tomorrowD);
// 本周周一的时间
var mondayTime = timestamp - ((serverDate.getDay() - 1) * 24 * 60 * 60 * 1000)
var mondayData = new Date(mondayTime);
// 年
var mondayY = mondayData.getFullYear();
// 月
var mondayM = (mondayData.getMonth() + 1 < 10 ? '0' + (mondayData.getMonth() + 1) : mondayData.getMonth() + 1);
// 日
var mondayD = mondayData.getDate() < 10 ? '0' + mondayData.getDate() : mondayData.getDate();
// 时
var mondayH = mondayData.getHours() < 10 ? '0' + mondayData.getHours() : mondayData.getHours();
// 分
var mondayMinu = mondayData.getMinutes() < 10 ? '0' + mondayData.getMinutes() : mondayData.getMinutes();
// 秒
var mondayS = mondayData.getSeconds() < 10 ? '0' + mondayData.getSeconds() : mondayData.getSeconds();
// 下周周一的时间
var nextMondayTiem = timestamp + ((8 - serverDate.getDay()) * 24 * 60 * 60 * 1000)
var nextMondayData = new Date(nextMondayTiem);
// 年
var nextMondY = nextMondayData.getFullYear();
// 月
var nextMondM = (nextMondayData.getMonth() + 1 < 10 ? '0' + (nextMondayData.getMonth() + 1) : nextMondayData.getMonth() + 1);
// 日
var nextMondD = nextMondayData.getDate() < 10 ? '0' + nextMondayData.getDate() : nextMondayData.getDate();
console.log('下周一: ' + nextMondY + '-' + nextMondM + '-' + nextMondD);
// 输出值
var config = {
SunDay: tomorrowY + '-' + tomorrowM + '-' + tomorrowD,
Monday: mondayY + '-' + mondayM + '-' + mondayD + ' ' + mondayH + ':' + mondayMinu + ':' + mondayS,
nextMonday: nextMondY + '-' + nextMondM + '-' + nextMondD
}
return config;
}
function getNextMondayTime() {
// 获取当天0点时间戳
var timestamp = new Date(new Date().setHours(0,0,0,0)).getTime();
var serverDate = new Date(timestamp);
// 下周周一的时间
var nextMondayTiem = timestamp + ((8 - serverDate.getDay()) * 24 * 60 * 60 * 1000)
var nextMondayData = new Date(nextMondayTiem);
console.log(nextMondayTiem);
console.log(nextMondayData);
// 年
var nextMondY = nextMondayData.getFullYear();
// 月
var nextMondM = (nextMondayData.getMonth() + 1 < 10 ? '0' + (nextMondayData.getMonth() + 1) : nextMondayData.getMonth() + 1);
// 日
var nextMondD = nextMondayData.getDate() < 10 ? '0' + nextMondayData.getDate() : nextMondayData.getDate();
// 时
var nextMondH = nextMondayData.getHours() < 10 ? '0' + nextMondayData.getHours() : nextMondayData.getHours();
// 分
var nextMondMinu = nextMondayData.getMinutes() < 10 ? '0' + nextMondayData.getMinutes() : nextMondayData.getMinutes();
// 秒
var nextMondS = nextMondayData.getSeconds() < 10 ? '0' + nextMondayData.getSeconds() : nextMondayData.getSeconds();
// 输出值
var config = {
nextMonday: nextMondY + '-' + nextMondM + '-' + nextMondD + ' ' + nextMondH + ':' + nextMondMinu + ':' + nextMondS
}
return config;
}
// 获取下周周一0点时间戳
function getNextMondayTime() {
// 获取当天0点时间戳
var timestamp = new Date(new Date().setHours(0,0,0,0)).getTime();
var serverDate = new Date(timestamp);
// 下周周一的时间戳
var nextMondayTiem = timestamp + ((8 - serverDate.getDay()) * 24 * 60 * 60 * 1000);
return nextMondayTiem;
}