一、js判断日期是否已经过期 传参格式 2018-5-20 过期返回false 没有返回true
function(date){
var normalizeDate = date.split("-");
var Month = new Date().getMonth() + 1;
var year = new Date().getFullYear();
if (normalizeDate[0] < year) {
return false
} else if(normalizeDate[0] == year){
if (normalizeDate[1] < Month) {
console.log(normalizeDate[1]< Month)
return false;
}else if(normalizeDate[1] == Month){
if (normalizeDate[2] < this.day) {
return false;
}else {
return true;
};
}else {
return true;
};
} else{
return true;
};
}
二、判断年月是否过期
function(date){
var normalizeDate = date.split("-");
var Month = new Date().getMonth() + 3;
var year = new Date().getFullYear();
if (normalizeDate[0] < year) {
return false
} else if(normalizeDate[0] == year){
if (normalizeDate[1] < Month) {
console.log(normalizeDate[1]< Month)
return false;
}else if(normalizeDate[1] == Month){
return true;
}else {
return true;
};
} else{
return true;
};
}
网友评论