身份证号工具类
/** 中国公民身份证号码最小长度。 */ 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; }
本文来自博客园,作者:小辉辉。。,转载请注明原文链接:https://www.cnblogs.com/zjylsh/p/15507399.html