身份证号工具类

    /** 中国公民身份证号码最小长度。 */
    public  final int CHINA_ID_MIN_LENGTH = 15;
    /** 中国公民身份证号码最大长度。 */
    public  final int CHINA_ID_MAX_LENGTH = 18;
    /**
     * @description: get the age of the IdCard
     */
    public static int getAgeByIdCard(String idCard) {
        String year = idCard.substring(6, 10);
        return LocalDate.now().getYear() - Integer.valueOf(year);
    }
    /**
     * @description: get the birth(yyyyMMdd) of the IdCard
     */
    public static String getBirthByIdCard(String idCard) {
        return idCard.substring(6, 14);
    }
    /**
     * @description: get the sex of the IdCard
     */
    public static int getSexByIdCard(String idCard) {
        int sex = 0;
        String sCardNum = idCard.substring(16, 17);
        if (Integer.parseInt(sCardNum) % 2 != 0) {
            sex = 1;//
        } else {
            sex = 2;//
        }
        return sex;
    }

 

posted @ 2021-11-04 11:22  小辉辉。。  阅读(37)  评论(0编辑  收藏  举报