身份證號工具類
阿新 • • 發佈:2021-11-04
/** 中國公民身份證號碼最小長度。 */ 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; }
本文來自部落格園,作者:小輝輝。。