比如传入'1991-6-3'返回true传递'2001-6-3'返回false
1 回答
拉丁的传说
TA贡献1789条经验 获得超8个赞
function getAge(dateString) {
var today = new Date();
var birthDate = new Date(dateString);
var age = today.getFullYear() - birthDate.getFullYear();
var m = today.getMonth() - birthDate.getMonth();
if (m < 0 || (m === 0 && today.getDate() < birthDate.getDate())) {
age--;
}
return age > 18;
}
console.log(getAge('1997-11-09'))
添加回答
举报
0/150
提交
取消