|
@ -17,7 +17,6 @@ import java.util.concurrent.ExecutionException;
|
|
public class IdCardUtil {
|
|
public class IdCardUtil {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// /**
|
|
// /**
|
|
// * 根据身份证的号码算出当前身份证持有者的年龄
|
|
// * 根据身份证的号码算出当前身份证持有者的年龄
|
|
// *
|
|
// *
|
|
@ -65,31 +64,36 @@ public class IdCardUtil {
|
|
* @throws Exception
|
|
* @throws Exception
|
|
*/
|
|
*/
|
|
public static int getAgeForIdcard(String idcard) {
|
|
public static int getAgeForIdcard(String idcard) {
|
|
int age = 0;
|
|
|
|
|
|
try {
|
|
|
|
int age = 0;
|
|
|
|
|
|
if (StringUtils.isEmpty(idcard)) {
|
|
|
|
return age;
|
|
|
|
}
|
|
|
|
|
|
if (StringUtils.isEmpty(idcard)) {
|
|
|
|
return age;
|
|
|
|
}
|
|
|
|
|
|
String birth = "";
|
|
|
|
|
|
String birth = "";
|
|
|
|
|
|
if (idcard.length() == 18) {
|
|
|
|
birth = idcard.substring(6, 14);
|
|
|
|
} else if (idcard.length() == 15) {
|
|
|
|
birth = "19" + idcard.substring(6, 12);
|
|
|
|
}
|
|
|
|
|
|
if (idcard.length() == 18) {
|
|
|
|
birth = idcard.substring(6, 14);
|
|
|
|
} else if (idcard.length() == 15) {
|
|
|
|
birth = "19" + idcard.substring(6, 12);
|
|
|
|
}
|
|
|
|
|
|
int year = Integer.valueOf(birth.substring(0, 4));
|
|
|
|
int month = Integer.valueOf(birth.substring(4, 6));
|
|
|
|
int day = Integer.valueOf(birth.substring(6));
|
|
|
|
Calendar cal = Calendar.getInstance();
|
|
|
|
age = cal.get(Calendar.YEAR) - year;
|
|
|
|
//周岁计算
|
|
|
|
if (cal.get(Calendar.MONTH) < (month - 1) || (cal.get(Calendar.MONTH) == (month - 1) && cal.get(Calendar.DATE) < day)) {
|
|
|
|
age--;
|
|
|
|
}
|
|
|
|
|
|
int year = Integer.valueOf(birth.substring(0, 4));
|
|
|
|
int month = Integer.valueOf(birth.substring(4, 6));
|
|
|
|
int day = Integer.valueOf(birth.substring(6));
|
|
|
|
Calendar cal = Calendar.getInstance();
|
|
|
|
age = cal.get(Calendar.YEAR) - year;
|
|
|
|
//周岁计算
|
|
|
|
if (cal.get(Calendar.MONTH) < (month - 1) || (cal.get(Calendar.MONTH) == (month - 1) && cal.get(Calendar.DATE) < day)) {
|
|
|
|
age--;
|
|
|
|
}
|
|
|
|
|
|
|
|
return age;
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
return age;
|
|
|
|
|
|
}
|
|
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@ -118,6 +122,7 @@ public class IdCardUtil {
|
|
}
|
|
}
|
|
return b;
|
|
return b;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* 根据身份证的号码算出当前身份证持有者的性别
|
|
* 根据身份证的号码算出当前身份证持有者的性别
|
|
* 1 女 2 男 3未知
|
|
* 1 女 2 男 3未知
|
|
@ -152,6 +157,7 @@ public class IdCardUtil {
|
|
}
|
|
}
|
|
return sex;
|
|
return sex;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* 根据身份证的号码算出当前身份证持有者的性别
|
|
* 根据身份证的号码算出当前身份证持有者的性别
|
|
* 1 男 2 女 3未知
|
|
* 1 男 2 女 3未知
|
|
@ -162,23 +168,28 @@ public class IdCardUtil {
|
|
public static String getSexForIdcard_new(String CardCode)
|
|
public static String getSexForIdcard_new(String CardCode)
|
|
throws Exception {
|
|
throws Exception {
|
|
String sex = Constant.level_sex_3;
|
|
String sex = Constant.level_sex_3;
|
|
if (CardCode.length() == 18) {
|
|
|
|
if (Integer.parseInt(CardCode.substring(16).substring(0, 1)) % 2 == 0) {// 判断性别
|
|
|
|
// modifid by lyr 2016-09-29
|
|
|
|
sex = Constant.level_sex_2;
|
|
|
|
// modifid by lyr 2016-09-29
|
|
|
|
} else {
|
|
|
|
// modifid by lyr 2016-09-29
|
|
|
|
sex = Constant.level_sex_1;
|
|
|
|
// modifid by lyr 2016-09-29
|
|
|
|
}
|
|
|
|
} else if (CardCode.length() == 15) {
|
|
|
|
String usex = CardCode.substring(14, 15);// 用户的性别
|
|
|
|
if (Integer.parseInt(usex) % 2 == 0) {
|
|
|
|
sex = Constant.level_sex_2;
|
|
|
|
} else {
|
|
|
|
sex = Constant.level_sex_1;
|
|
|
|
|
|
try {
|
|
|
|
if (CardCode.length() == 18) {
|
|
|
|
if (Integer.parseInt(CardCode.substring(16).substring(0, 1)) % 2 == 0) {// 判断性别
|
|
|
|
// modifid by lyr 2016-09-29
|
|
|
|
sex = Constant.level_sex_2;
|
|
|
|
// modifid by lyr 2016-09-29
|
|
|
|
} else {
|
|
|
|
// modifid by lyr 2016-09-29
|
|
|
|
sex = Constant.level_sex_1;
|
|
|
|
// modifid by lyr 2016-09-29
|
|
|
|
}
|
|
|
|
} else if (CardCode.length() == 15) {
|
|
|
|
String usex = CardCode.substring(14, 15);// 用户的性别
|
|
|
|
if (Integer.parseInt(usex) % 2 == 0) {
|
|
|
|
sex = Constant.level_sex_2;
|
|
|
|
} else {
|
|
|
|
sex = Constant.level_sex_1;
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
return sex;
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
return sex;
|
|
return sex;
|
|
}
|
|
}
|