1. 程式人生 > 其它 >身份證號工具類

身份證號工具類

    /** 中國公民身份證號碼最小長度。 */
    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