function addDate(date, days) {
if (days == undefined || days == '') {
days = 1;
}
var date = new Date(date);
date.setDate(date.getDate() + days);
var month = date.getMonth() + 1; //月份从0开始所以需要+1
var day = date.getDate();
return date.getFullYear() + '-' + getFormatDate(month) + '-' + getFormatDate(day);
}
function getFormatDate(arg) {
if (arg == undefined || arg == '') {
return '';
}
var re = arg + '';
if (re.length < 2) {
re = '0' + re;
}
return re;
}
var edate = addDate('2021-08-22',30);
var sdate = addDate('2021-08-22',-30);
function getisrange(dt,s1,s2){
//var dt = new Date(dt.replace(/\-/g, "\/"));
//var s1 = new Date(s1.replace(/\-/g, "\/"));
//var s2 = new Date(s2.replace(/\-/g, "\/"));
if(dt >= s1 && dt <= s2){
return true;
}
else{
return false;
}
}
console.log(edate.replace(/\-/g, "\/"));
console.log(sdate,edate);
console.log(getisrange('2021-09-21',sdate,edate));
console