// 点击昨天
function checkYesterday() {
var yesterday = myDate.getFullYear() + '-' + (myDate.getMonth() + 1) + '-' + (myDate.getDate() - 1)////昨天
if (myDate.getDate() == 1) {
var yesterday = myDate.getFullYear() + '-' + myDate.getMonth() + '-' + laydate.getEndDate(myDate.getMonth());
if (myDate.getMonth() == 0) {
var yesterday = myDate.getFullYear() - 1 + '-12-31'
}
}
console.log(yesterday)
}
// 点击本周
function checkThisWeek() {
var week = myDate.getDay();
(week == 0) ? 7 : myDate.getDate()//星期几
var weekStart = myDate.getDate() - (week - 1)
var weekEnd = myDate.getDate() + 6 - (week - 1)
console.log(week)
console.log(weekStart)
console.log(weekEnd)
if (weekStart <= 0) {
if (myDate.getMonth() == 0) {
currentYear = myDate.getFullYear() - 1;
currentMonth = 12
} else {
currentYear = myDate.getFullYear();
currentMonth = myDate.getMonth()
}
weekStart = weekStart + laydate.getEndDate(myDate.getMonth());
weekStart = currentYear + '-' + currentMonth + '-' + weekStart
weekEnd = myDate.getFullYear() + '-' + (myDate.getMonth() + 1) + '-' + weekEnd
} else if (weekEnd > laydate.getEndDate(myDate.getMonth() + 1)) {
if (myDate.getMonth() + 1 == 12) {
currentYear = myDate.getFullYear() + 1;
currentMonth = 1
} else {
currentYear = myDate.getFullYear();
currentMonth = myDate.getMonth() + 1 + 1
}
weekStart = myDate.getFullYear() + '-' + (myDate.getMonth() + 1) + '-' + weekStart
weekEnd = weekEnd - laydate.getEndDate(myDate.getMonth() + 1)
weekEnd = currentYear + '-' + currentMonth + '-' + weekEnd
} else {
weekStart = myDate.getFullYear() + '-' + (myDate.getMonth() + 1) + '-' + weekStart
weekEnd = myDate.getFullYear() + '-' + (myDate.getMonth() + 1) + '-' + weekEnd
}
var currentWeek = weekStart + " - " + weekEnd
console.log(currentWeek)
}
// 上周
function checkLastWeek() {
var week = myDate.getDay();
(week == 0) ? 7 : myDate.getDate()//星期几
var weekStart = myDate.getDate() - (week - 1) - 7
var weekEnd = myDate.getDate() + 6 - (week - 1) - 7
console.log(weekStart)
console.log(weekEnd)
if (weekStart <= 0) {
if (myDate.getMonth() == 0) {
currentYear = myDate.getFullYear() - 1;
currentMonth = 12
} else {
currentYear = myDate.getFullYear();
currentMonth = myDate.getMonth()
}
weekStart = weekStart + laydate.getEndDate(myDate.getMonth());
weekStart = currentYear + '-' + currentMonth + '-' + weekStart
if (weekEnd <= 0) {
weekEnd = weekEnd + laydate.getEndDate(myDate.getMonth());
if (myDate.getMonth() == 0) {
month = 12
year = myDate.getFullYear() - 1
} else {
month = myDate.getMonth()
year = myDate.getFullYear()
}
weekEnd = year + '-' + month + '-' + weekEnd
} else {
weekEnd = myDate.getFullYear() + '-' + (myDate.getMonth() + 1) + '-' + weekEnd
}
} else if (weekEnd > laydate.getEndDate(myDate.getMonth() + 1)) {
if (myDate.getMonth() + 1 == 12) {
currentYear = myDate.getFullYear() + 1;
currentMonth = 1
} else {
currentYear = myDate.getFullYear();
currentMonth = myDate.getMonth() + 2
}
weekEnd = weekEnd - laydate.getEndDate(myDate.getMonth() + 1)
weekStart = myDate.getFullYear() + '-' + (myDate.getMonth() + 1) + '-' + weekStart
weekEnd = currentYear + '-' + currentMonth + '-' + weekEnd
} else {
weekStart = myDate.getFullYear() + '-' + (myDate.getMonth() + 1) + '-' + weekStart
weekEnd = myDate.getFullYear() + '-' + (myDate.getMonth() + 1) + '-' + weekEnd
}
var lastWeek = weekStart + " - " + weekEnd
console.log(lastWeek)
}
// 本月
function checkThisMonth() {
if (laydate.getEndDate(myDate.getMonth() + 1) == 28 || laydate.getEndDate(myDate.getMonth() + 1) == 29) {
monthStart = myDate.getFullYear() + '-2-1'
monthEnd = myDate.getFullYear() + '-2-' + myDate.getDate()
} else if (laydate.getEndDate(myDate.getMonth() + 1) == 30) {
monthStart = myDate.getFullYear() + '-' + (myDate.getMonth() + 1) + '-1';
monthEnd = myDate.getFullYear() + '-' + (myDate.getMonth() + 1) + '-30'
} else if (laydate.getEndDate(myDate.getMonth() + 1) == 31) {
monthStart = myDate.getFullYear() + '-' + (myDate.getMonth() + 1) + '-1';
monthEnd = myDate.getFullYear() + '-' + (myDate.getMonth() + 1) + '-31'
}
var thisMonth = monthStart + " - " + monthEnd
console.log(thisMonth)
}
原生的明天
function tomorrow(date) {
var date = new Date(date);
date =date.getTime()+ 24*60*60*1000;
console.log((new Date(date)));
}