js calculated according to age, date of birth

function getAge(str){   
    var r = str.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/);     
    if(r==null)return   false;     
    var d= new Date(r[1],r[3]-1,r[4]);
    if(d.getFullYear()==r[1]&&(d.getMonth()+1)==r[3]&&d.getDate()==r[4]){   
        var date = new Date();
        var Y   =   date.getFullYear() - r[1];
        var M = date.getMonth() + 1 - r[3];
        var D = date.getDate();
        if(the parseInt (D) - the parseInt (R & lt [. 4]) <0 ) { 
            M - ;
             IF (M <0 ) { 
                the Y - ; 
                M =. 11 ; 
            } 
        } 
        IF (M <0 ) { 
            the Y - ; 
            M . 11 = ; 
        } 
        return (the Y + "the Y '+ M +" M " );    
    }    
    return (" date format entered wrong! " );    
}

 

Guess you like

Origin www.cnblogs.com/zhanglw456/p/11429626.html