gistfile1.txt /** * 根据身份证号获取年龄(周岁) * @param idCard 身份证 * @return 年龄 */ public static int getFullAgeByIdCard(String idCard){ Calendar cal1 = Calendar.getInstance(); Calendar today = Calendar.getInstance(); c
/** * 根据身份证号获取年龄(周岁) * @param idCard 身份证 * @return 年龄 */ public static int getFullAgeByIdCard(String idCard){ Calendar cal1 = Calendar.getInstance(); Calendar today = Calendar.getInstance(); cal1.set(Integer.parseInt(idCard.substring(6,10)), Integer.parseInt(idCard.substring(10,12)), Integer.parseInt(idCard.substring(12,14))); int m = (today.get(today.MONTH))+1 - (cal1.get(cal1.MONTH)); int y = (today.get(today.YEAR)) - (cal1.get(cal1.YEAR)); int d = (today.get(today.DAY_OF_MONTH)) - (cal1.get(cal1.DAY_OF_MONTH)); if (m <= 0){ if (m == 0){ if (d < 0) y--; }else { y--; } } return y; }