Javaでは、年齢、性別、生年月日を身分証明書でどのように解析しますか.


Javaでは、年齢、性別、生年月日を身分証明書でどのように解析しますか.次は私が書いたjavaクラスです
package com.thinkgem.jeesite.modules.cyry;
import com.thinkgem.jeesite.modules.wcbxx.dao.WcbxxDao;
import com.thinkgem.jeesite.modules.wcbxx.entity.Wcbxx;
import com.thinkgem.jeesite.modules.wcbxx.service.WcbxxService;


import java.util.Calendar;
import java.util.List;

/**
 * Created by Administrator on 2016/2/25.
 */
public class IdCard {
    /**              。 */
    public  final int CHINA_ID_MIN_LENGTH = 15;

    /**              。 */
    public  final int CHINA_ID_MAX_LENGTH = 18;
    /**
     *           
     *
     * @param idCard
     *                
     * @return   
     */
    public static int getAgeByIdCard(String idCard) {
        int iAge = 0;
        Calendar cal = Calendar.getInstance();
        String year = idCard.substring(6, 10);
        int iCurrYear = cal.get(Calendar.YEAR);
        iAge = iCurrYear - Integer.valueOf(year);
        return iAge;
    }

    /**
     *           
     *
     * @param idCard     
     * @return   (yyyyMMdd)
     */
    public static String getBirthByIdCard(String idCard) {
        return idCard.substring(6, 14);
    }

    /**
     *            
     *
     * @param idCard     
     * @return   (yyyy)
     */
    public static Short getYearByIdCard(String idCard) {
        return Short.valueOf(idCard.substring(6, 10));
    }

    /**
     *            
     *
     * @param idCard
     *                
     * @return   (MM)
     */
    public static Short getMonthByIdCard(String idCard) {
        return Short.valueOf(idCard.substring(10, 12));
    }

    /**
     *            
     *
     * @param idCard
     *                
     * @return   (dd)
     */
    public static Short getDateByIdCard(String idCard) {
        return Short.valueOf(idCard.substring(12, 14));
    }

    /**
     *           
     *
     * @param idCard     
     * @return   (M- F- N-  )
     */
    public static String getGenderByIdCard(String idCard) {
        String sGender = "  ";

        String sCardNum = idCard.substring(16, 17);
        if (Integer.parseInt(sCardNum) % 2 != 0) {
            sGender = "1";// 
        } else {
            sGender = "2";// 
        }
        return sGender;
    }

//       
 /*   @RequestMapping(value = "shebaoshuju",method = RequestMethod.GET)
    public String shebaoshuju(){
        List list= wcbxxservice.all();
        int  cou=0;
        for(Wcbxx w:list){
            if(w.getIdcard()!=null && w.getIdcard().length()>17) {
                String sex = IdCard.getGenderByIdCard(w.getIdcard());
                int age = IdCard.getAgeByIdCard(w.getIdcard());
                w.setAge(Long.valueOf(age));
                w.setSex(sex);
                int a = wcbxxservice.updatess(w);
                if (a>0) {
                    System.out.println("  " + w.getRname() + "   " + w.getIdcard() + "  :" + age + "  :" + sex);
                }
            }
            cou++;
            System.out.println(cou);
        }
        return "";
    }*/

    @Test
    public static  void  main(String [] a){
        String idcard="460200199209275127";
        String sex= getGenderByIdCard(idcard);
        System.out.println("  :" + sex);
        int age= getAgeByIdCard(idcard);
        System.out.println("  :" + age);
        Short nian=getYearByIdCard(idcard);
        Short yue=getMonthByIdCard(idcard);
        Short ri=getDateByIdCard(idcard);
        System.out.print(nian+" "+yue+" "+ri+" ");

        String sr=getBirthByIdCard(idcard);
        System.out.println("  :" + sr);
    }

}