import java.text.SimpleDateFormat;
import java.util.Date;
//身份证处理
public class IDUtils {
/**
* 根据身份证计算年龄
* @param IdNO
* @return
*/
public static int IdNOToAge(String IdNO){
int leh = IdNO.length();
String dates="";
if (leh == 18) {
int se = Integer.valueOf(IdNO.substring(leh - 1)) % 2;
dates = IdNO.substring(6, 10);
SimpleDateFormat df = new SimpleDateFormat("yyyy");
String year=df.format(new Date());
int u=Integer.parseInt(year)-Integer.parseInt(dates);
return u;
}else{
dates = IdNO.substring(6, 8);
return Integer.parseInt(dates);
}
}
/**
* 根据身份证计算性别
* @param IdNO
* @return
*/
public static String IdNOToSex(String IdNO){
int leh = IdNO.length();
String sex="";
if (leh == 18) {
if (Integer.parseInt(IdNO.substring(16).substring(0, 1)) % 2 == 0) {
sex = "女";
} else {
sex = "男";
}
}else{
String usex = IdNO.substring(14, 15);
if (Integer.parseInt(usex) % 2 == 0) {
sex = "女";
} else {
sex = "男";
}
}
return sex;
}
}