ID number to determine the age of

Integer public checkExpertAge (String idCard) {
     //   1. obtain identity cards of birth, month, day 
    Integer = personYear Integer.parseInt (idCard.substring ( 6 , 10 )); 
    Integer personMonth = Integer.parseInt (idCard.substring ( 10 , 12 )); 
    Integer personDay = Integer.parseInt (idCard.substring ( 12 , 14 ));
     //   2. get the current time of year, month, day 
    Calendar CAL = Calendar.getInstance (); 
    Integer yearNow = CAL . GET (Calendar.YEAR); 
    Integer monthNow = CAL. GET(Of the Calendar.MONTH) + 1 ; 
    Integer dayNow . CAL = GET (Calendar.DATE);
     //   3. minus birthday date with the current date 
    Integer yearMinus = yearNow - personYear; 
    Integer monthMinus = monthNow - personMonth; 
    Integer dayMinus = dayNow - personDay;
     //   4. Analyzing the age 
    Integer Age = yearMinus;
     if (yearMinus == 0 ) {
         //   the year is the current year of birth 
        Age = 0 ; 
    } the else {
         //   birth year is greater than the current year 
        if(monthMinus < 0 ) {
             //   birth month less than the current month, a year old not 
            Age Age = - . 1 ; 
        } 
        IF (monthMinus == 0 ) {
             //   current month is the month of birth, date of determination 
            IF (dayMinus < 0 ) {
                 //   when less than the current date of birth, month, year old not 
                Age Age = - . 1 ; 
            } 
        } 
    } return  Age ; 
}

 

Guess you like

Origin www.cnblogs.com/shiblog/p/11613156.html
Recommended