Date.prototype.format = function (fmt) {
const o = {
"M+": this.getMonth() + 1,
"d+": this.getDate(),
"h+": this.getHours(),
"m+": this.getMinutes(),
"s+": this.getSeconds(),
"q+": Math.floor((this.getMonth() + 3) / 3),
"S": this.getMilliseconds()
};
if (/(y+)/.test(fmt)) {
fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
}
for (var k in o) {
if (new RegExp("(" + k + ")").test(fmt)) {
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
}
}
return fmt;
}
function previousMonthFirst() {
let currentDate = new Date();
currentDate.setMonth(currentDate.getMonth() - 1)
const y = currentDate.getFullYear();
let m = currentDate.getMonth() + 1;
m = m < 10 ? "0" + m : m;
return [y, m, '01'].join("-");
}
function previousMonthLast() {
const currentDate = new Date();
const y = currentDate.getFullYear();
let m = currentDate.getMonth() + 1;
m = m < 10 ? "0" + m : m;
const currentDate2 = new Date([y, m, '01'].join("-"))
currentDate2.setDate(currentDate2.getDate() - 1)
return currentDate2.format("yyyy-MM-dd")
}
function currentMonthFirst() {
const currentDate = new Date();
const y = currentDate.getFullYear();
let m = currentDate.getMonth() + 1;
m = m < 10 ? "0" + m : m;
return [y, m, "01"].join("-");
}
function currentMonthLast() {
const currentDate = new Date()
currentDate.setMonth(currentDate.getMonth() + 1)
let y = currentDate.getFullYear()
let m = currentDate.getMonth() + 1
m = m < 10 ? "0" + m : m
const monthLast = new Date([y, m, '01'].join('-'));
monthLast.setDate(monthLast.getDate() - 1)
return monthLast.format("yyyy-MM-dd")
}
function nextMonthFirst() {
const nextFirst = new Date()
nextFirst.setMonth(nextFirst.getMonth() + 1)
const nextOne2 = new Date([nextFirst.getFullYear(), nextFirst.getMonth() + 1, '01'].join('-'));
return nextOne2.format("yyyy-MM-dd")
}
function nextMonthLast() {
const nextLast = new Date()
nextLast.setMonth(nextLast.getMonth() + 2)
let y = nextLast.getFullYear()
let m = nextLast.getMonth() + 1
m = m < 10 ? "0" + m : m
const nextLast2 = new Date([y, m, '01'].join('-'));
nextLast2.setDate(nextLast2.getDate() - 1)
return nextLast2.format("yyyy-MM-dd")
}
const now = new Date();
const nowTime = now.getTime();
const day = now.getDay();
const oneDayTime = 24 * 60 * 60 * 1000;
let BMondayTime = nowTime - (day - 1) * oneDayTime;
let BSundayTime = nowTime + (7 - day) * oneDayTime;
BMondayTime = new Date(BMondayTime).format("yyyy-MM-dd");
BSundayTime = new Date(BSundayTime).format("yyyy-MM-dd");
let SMondayTime = nowTime - (day + 6) * oneDayTime;
let SSundayTime = nowTime + (0 - day) * oneDayTime;
SMondayTime = new Date(SMondayTime).format("yyyy-MM-dd");
SSundayTime = new Date(SSundayTime).format("yyyy-MM-dd");
let AMondayTime = nowTime - (day - 8) * oneDayTime;
let ASundayTime = nowTime + (8 + day) * oneDayTime;
AMondayTime = new Date(AMondayTime).format("yyyy-MM-dd");
ASundayTime = new Date(ASundayTime).format("yyyy-MM-dd");