2018年1月8日
js年龄限制最大最小日期,主要是闰年的判断
var years, year, maxYear, month, twenty, ninety, minDay, maxDay, day_s;
years = Date.parse(new Date());
twenty = 365 * 24 * 3600 * 1000 * 20;//最小20岁
ninety = 365 * 24 * 3600 * 1000 * 90;//最大90岁
year = new Date(years - ninety).getFullYear();
maxYear = new Date(years - twenty).getFullYear();
month = new Date().getMonth() + 1;
day_s = new Date().getDate();
if(month < 10){
month = '0' + month;
}
if(day_s < 10){
day_s = '0' + day_s;
}
if ((year%4==0&&year%100!=0)||year%400==0){
if(month == 2){
minDay = year + '-' + month + '-' + 29;
}else{
minDay = year + '-' + month + '-' + day_s;
}
}else{
if(month == 2){
minDay = year + '-' + month + '-' + 28;
}else{
minDay = year + '-' + month + '-' + day_s;
}
}
if ((maxYear%4==0&&maxYear%100!=0)||maxYear%400==0){
if(month == 2){
maxDay = maxYear + '-' + month + '-' + 29;
}else{
maxDay = maxYear + '-' + month + '-' + day_s;
}
}else{
if(month == 2){
maxDay = maxYear + '-' + month + '-' + 28;
}else{
maxDay = maxYear + '-' + month + '-' + day_s;
}
}
console.log(minDay);
console.log(maxDay);