Package com.zysoft.own_demo.utils;
Import Java.text.SimpleDateFormat;
Import Java.util.Date; /** * @author Huang Jipo * @date 2018/1/18/public class Idcardutil {/** * get birthday * @param cardcode * @r
Eturn */public static string Getbirthdaybyidcard (String cardcode) {Integer len = cardcode.length ();
String Bir;
if (len==18) {bir = GetBirthdayByIdCard18 (Cardcode);
}else{bir = getBirthdayByIdCard15 (Cardcode);
return BIR; /** * Get Age * @param cardcode * @return/public static string Getagebyidcard (String CARDC
Ode) {Integer len = cardcode.length ();
String age;
if (len==18) {age = GetAgeByIdCard18 (Cardcode);
}else{age = GetAgeByIdCard15 (Cardcode);
return to age; /** * Access to Gender * @param cardcode * @return/public static string Getsexbyidcard (String CARDCOde) {Integer len = cardcode.length ();
String sex;
if (len==18) {sex = GetSexByIdCard18 (Cardcode);
}else{sex = getSexByIdCard15 (Cardcode);
return sex; /** * 18 ID * Get birthday * @param cardcode * @return * * private static String Getbirthdayb
YIdCard18 (String cardcode) {//id date string idyear = Cardcode.substring (6). substring (0, 4)/year String Idyue = cardcode.substring. substring (0, 2);//Get month String Idday = cardcode.substring (a). substring
(0, 2);//Get day String bir = idyear+ "-" +idyue + "-" + idday;
return BIR; /** * 18 ID Card * Access to Gender * @param cardcode * @return * * private static String GETSEXBYIDCA Rd18 (String cardcode) {string sex = "2";//Unknown if (Integer.parseint (cardcode.substring). substring (0, 1)
% 2 = 0) {//judge sex sex = "0";//woman} else { Sex = "1";
man} return sex; /** * 18 ID Card * Acquisition age * @param cardcode * @return * * private static String GETAGEBYIDCA Rd18 (String cardcode) {//id date string idyear = Cardcode.substring (6). substring (0, 4);//Get year S Tring Idyue = cardcode.substring. substring (0, 2);//Get month String Idday = cardcode.substring (a) substring (0, 2)
//Get day String Idyr = Idyue + Idday + ""; Current Month Day string year = new SimpleDateFormat ("Yyyy-mm-dd"). Format (new Date ()). Substring (0, 4);//Current year String Yue = new SimpleDateFormat ("Yyyy-mm-dd"). Format (new Date ()). SUBSTRING (5, 7);//month String day = new Simpledateform
at ("Yyyy-mm-dd"). Format (new Date ()). SUBSTRING (8, 10);
String yr = Yue + day + "";
int age = 0; if (Integer.parseint (Idyr) <= integer.parseint (yr)) {//indicates that the birthday is over age = integer.parseint (year)-Integer.pars
Eint (idyear) + 1; else {//Birthday is not over age = integer.parseint (year)-Integer.parseint (idyear);
Return to Age + ""; /** * 15 ID * Get birthday * @param cardcode * @return * * private static String Getbirthdayb
YIdCard15 (String cardcode) {//id date String idyear = "n" + cardcode.substring (6, 8);
String Idyue = cardcode.substring (8, 10);
String idday = cardcode.substring (10, 12);
String bir = idyear+ "-" +idyue + "-" + idday;
return BIR; /** * 15 ID Card * Access to Gender * @param cardcode * @return * * private static String GETSEXBYIDCA Rd15 (String cardcode) {string sex = "2";//Unknown if (Integer.parseint (cardcode.substring (14, 15))% 2 = = 0)
{//judge sex sex = "0";///woman} else {sex = "1";//man} return sex; /** * 15 ID Card * Acquisition age * @param cardcode * @return * * private static String GETAGEBYIDCA Rd15 (String Cardcode) {//ID card on the month-day String idyear = "a" + cardcode.substring (6, 8);
String Idyue = cardcode.substring (8, 10);
String idday = cardcode.substring (10, 12);
String Idyr = Idyue + Idday + ""; Current Month Day string year = new SimpleDateFormat ("Yyyy-mm-dd"). Format (new Date ()). Substring (0, 4);//Current year String Yue = new SimpleDateFormat ("Yyyy-mm-dd"). Format (new Date ()). SUBSTRING (5, 7);//month String day = new Simpledateform
at ("Yyyy-mm-dd"). Format (new Date ()). SUBSTRING (8, 10);
String yr = Yue + day + "";
int age = 0; if (Integer.parseint (Idyr) <= integer.parseint (yr)) {//indicates that the birthday is over age = integer.parseint (year)-Integer.pars
Eint (idyear) + 1;
else {//birthday is not over age = integer.parseint (year)-Integer.parseint (idyear);
Return to Age + "";
}
}