根据身份证号 查询是否满18岁

时间:2022-12-08 23:17:12
function stuCardIdCanApplyByAge(cardId){
    var birthYear = cardId.substring(6,10);
    var birthMonth = cardId.substring(10,12);
    var birthDay = cardId.substring(12,14);
    var now = new Date();
    var year = now.getFullYear();
    var month = now.getMonth() +1;
    var day = now.getDate();
    var age = year - birthYear;
    if(age>18){
        return true;
    }else{
        if(age<18){
            return false;
        }else{
            if(birthMonth>month){
                return false;
            }else if(birthMonth<month){
                return true;
            }else{
                if(birthDay<=day){
                    return true;
                }else{
                    return false;
                }
            }
        }       
    }
}