java验证身份证号码及编码规则和提取相应信息
Java实现身份证校验(包括校验码地区时间)

Java实现⾝份证校验(包括校验码地区时间)public class IdCardUtils {//⾝份证前1位每位加权因⼦private static int[] power = {7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2};//⾝份证第18位校检码private static String[] refNumber ={"1", "0", "X", "9", "8", "7", "6", "5", "4", "3"};//省(直辖市)代码表private static String provinceCode[] = { "11", "12", "13", "14", "15", "21", "22","23", "31", "32", "33", "34", "35", "36", "37", "41", "42", "43","44", "45", "46", "50", "51", "52", "53", "54", "61", "62", "63","64", "65", "71", "81", "82", "91" };public static boolean checkIdCard(String idCard) {return checkCardIdLastNum(idCard) && (isValidDate(idCard.substring(6, 14))&& (checkProvinceId(idCard.substring(0, 2)) && isCardId(idCard)));}public static boolean isCardId(String cardid){return Pattern.matches("^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}([\\d|x|X]{1})$", cardid);}/*** 检查⾝份证的省份信息是否正确(使⽤与18/15位⾝份证)* @param provinceId* @return*/public static boolean checkProvinceId(String provinceId){for (String id : provinceCode) {if (id.equals(provinceId)) {return true;}}return false;}/*** 校验⾝份证第18位是否正确(只适合18位⾝份证)* @param cardId* @return*/public static boolean checkCardIdLastNum(String cardId){if(cardId.length() != 18){return false;}char[] tmp = cardId.toCharArray();int[] cardidArray = new int[tmp.length-1];int i=0;for(i=0;i<tmp.length-1;i++){cardidArray[i] = Integer.parseInt(tmp[i]+"");}String checkCode = sumPower(cardidArray);String lastNum = tmp[tmp.length-1] + "";if(lastNum.equals("x")){lastNum = lastNum.toUpperCase();}if(!checkCode.equals(lastNum)){return false;}return true;}/*** 计算⾝份证的第⼗⼋位校验码* @param cardIdArray* @return*/public static String sumPower(int[] cardIdArray){int result = 0;本⽂作者本⽂作者: 本⽂链接:关于博主:评论和私信会在第⼀时间回复。
身份证号码验证(15位和18位且最后一位是X时不区分大小写)

21."3","2"};
22.String[] Wi = {"7","9","10","5","8","4","2","1","6","3","7",
23."9","10","5","8","4","2"};
46.String strMonth = Ai.substring(10,12);// 月份
47.String strDay = Ai.substring(12,14);// 月份
48.if(isDataFormat(strYear +"-"+ strMonth +"-"+ strDay) ==false) {
72.
73.// ================ 判断最后一位的值 ================
74.intTotalmulAiWi =0;
75.for(inti =0; i <17; i++) {
76.TotalmulAiWi = TotalmulAiWi
77.+ Integer.parseInt(String.valueOf(Ai.charAt(i)))
java证件号正则

java证件号正则在Java中,验证证件号的正则表达式可以根据不同的证件类型进行匹配。
以下是一个通用的正则表达式,用于验证中国大陆居民的身份证号:```javaString regex = "^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2|3|4|5|6|7|8|9])\\d{3}) $";```这个正则表达式匹配的是18位身份证号,其中包括:1. 前6位:地区代码2. 接下来4位:出生年份3. 然后2位:出生月份4. 接着2位:出生日期5. 最后4位:顺序码,其中最后一位为校验码要使用这个正则表达式验证身份证号,你可以使用Java的`Pattern`和`Matcher`类:```javaimport java.util.regex.Matcher;import java.util.regex.Pattern;public class IDCardValidator {public static void main(String[] args) {StringidCard=*******************";String regex = "^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2|3|4|5|6|7|8|9])\\d{3}) $";Pattern pattern = pile(regex);Matcher matcher = pattern.matcher(idCard);if (matcher.matches()) {System.out.println("身份证号有效");} else {System.out.println("身份证号无效");}}}请注意,这个正则表达式仅适用于中国大陆的身份证号。
JAVA通过身份证号码获取出生日期、年龄、性别

JAVA通过⾝份证号码获取出⽣⽇期、年龄、性别JAVA验证⾝份证号码是否正确:/*** 通过⾝份证号码获取出⽣⽇期(birthday)、年龄(age)、性别(sex)* @param idCardNo ⾝份证号码* @return返回的出⽣⽇期格式:1993-05-07 性别格式:1:男,0:⼥*/public static Map<String, String> getBirthdayAgeSex(String idCardNo) {String birthday = "";String age = "";String sexCode = "";int year = Calendar.getInstance().get(Calendar.YEAR);char[] number = idCardNo.toCharArray();boolean flag = true;if (number.length == 15) {for (int x = 0; x < number.length; x++) {if (!flag){return new HashMap<String, String>();}flag = Character.isDigit(number[x]);}} else if (number.length == 18) {for (int x = 0; x < number.length - 1; x++) {if (!flag){return new HashMap<String, String>();}flag = Character.isDigit(number[x]);}}if (flag && idCardNo.length() == 15) {birthday = "19" + idCardNo.substring(6, 8) + "-"+ idCardNo.substring(8, 10) + "-"+ idCardNo.substring(10, 12);sexCode = Integer.parseInt(idCardNo.substring(idCardNo.length() - 3, idCardNo.length())) % 2 == 0 ? "0" : "1";age = (year - Integer.parseInt("19" + idCardNo.substring(6, 8))) + "";} else if (flag && idCardNo.length() == 18) {birthday = idCardNo.substring(6, 10) + "-"+ idCardNo.substring(10, 12) + "-"+ idCardNo.substring(12, 14);sexCode = Integer.parseInt(idCardNo.substring(idCardNo.length() - 4, idCardNo.length() - 1)) % 2 == 0 ? "0" : "1";age = (year - Integer.parseInt(idCardNo.substring(6, 10))) + "";}Map<String, String> map = new HashMap<String, String>();map.put("birthday", birthday);map.put("age", age);map.put("sex", sexCode);return map;}。
java 证件号码正则校验规则

java 证件号码正则校验规则摘要:一、Java中正则表达式的使用二、身份证号码正则校验规则1.整体结构2.校验位计算3.校验位规则三、护照号码正则校验规则1.整体结构2.护照号码格式四、港澳台通行证号码正则校验规则1.整体结构2.港澳台通行证号码格式五、实用示例正文:一、Java中正则表达式的使用在Java中,我们可以使用`Pattern`和`Matcher`类来进行正则表达式的匹配和校验。
通过引入`java.util.regex`包,我们可以方便地使用正则表达式对各种字符串进行校验。
二、身份证号码正则校验规则1.整体结构身份证号码由18位数字组成,包括地区代码、出生日期、顺序码和校验码。
2.校验位计算校验位采用加权因子计算,加权因子分别为7、9、10、5、8、4、2、1、6、3、7、9、10、5、8、4、2。
3.校验位规则校验位数字根据前17位数字的权重值计算得出,权重值依次为:1、3、7、9、10、5、8、4、2、6、1、3、7、9、10、5、8、4、2。
计算方法为:将前17位数字分别乘以对应的权重值,然后求和,最后除以11,取余数,对应校验码。
三、护照号码正则校验规则1.整体结构护照号码由9位数字组成,包括国家代码、地区代码、顺序码和校验码。
2.护照号码格式护照号码的国家代码和地区代码均为2位数字,顺序码为3位数字,校验码为1位数字。
四、港澳台通行证号码正则校验规则1.整体结构港澳台通行证号码由9位数字组成,包括地区代码、顺序码和校验码。
2.港澳台通行证号码格式地区代码为1位字母,顺序码为4位数字,校验码为1位数字。
java正则match用法总结

java正则match用法总结正则表达式在Java中是非常强大且常用的工具,它可以帮助我们在文本处理和模式匹配中实现灵活的操作。
本文将总结Java中`match`方法的用法,并介绍一些实用的正则表达式示例。
一、match方法的基本用法在Java中,`match`方法是用于检查指定的正则表达式是否与给定的字符串相匹配。
它的基本语法如下所示:```javaboolean matchResult = str.matches(regex);```其中,`str`是要匹配的字符串,`regex`是正则表达式。
`match`方法返回一个布尔值,如果匹配成功,则返回`true`,否则返回`false`。
二、常用的匹配规则1. 检查手机号码格式```javaString regex = "^1[3-9]\\d{9}$";boolean matchResult = str.matches(regex);```这个正则表达式用于检查11位手机号码的格式,以1开头,第二位是3-9之间的数字,后面跟着9位数字。
如果字符串与该正则表达式匹配,则表示手机号码格式正确。
2. 验证邮箱格式```javaString regex = "^[a-zA-Z0-9_]+@[a-zA-Z0-9]+(\\.[a-zA-Z]{2,3}){1,2}$";boolean matchResult = str.matches(regex);```这个正则表达式用于验证邮箱的格式,要求邮箱由字母、数字、下划线组成,然后是@符号,再后面是域名。
域名由字母和数字组成,可以有1个或2个点(.)作为分隔符,每个点后面跟着2或3个字母。
符合该正则表达式的字符串表示邮箱格式正确。
3. 匹配日期格式```javaString regex = "^\\d{4}-\\d{2}-\\d{2}$";boolean matchResult = str.matches(regex);```这个正则表达式用于匹配yyyy-MM-dd格式的日期,其中`\d`表示任意数字。
JAVA校验身份证号码工具类(支持15位和18位)

JAVA校验⾝份证号码⼯具类(⽀持15位和18位)JAVA 校验⾝份证号码⼯具类(⽀持15位和18位)import java.text.SimpleDateFormat;import java.util.Calendar;import java.util.GregorianCalendar;import java.util.Hashtable;import java.util.regex.Matcher;import java.util.regex.Pattern;/*** TODO* ⾝份证校验⼯具类*/public class IDCardUtil {/*校验规则:如果为15位,只能是15位数字;前两位满⾜省/直辖市的⾏政区划代码。
如果为18位,允许为18位数字,如出现字母只能在最后⼀位,且仅能为“X”;18位中包含年⽉的字段满⾜⽇期的构成规则;前两位满⾜省/直辖市的⾏政区划代码;最后⼀位校验位满⾜⾝份证的校验规则(⾝份证校验规则见附录)。
附录:⾝份证校验规则公民⾝份证号码校验公式为RESULT = ∑( A[i] * W[i] ) mod 11。
其中,i表⽰号码字符从右⾄左包括校验码在内的位置序号;A[i]表⽰第I位置上的数字的数值;W[i]表⽰第i位置上的加权因⼦,其值如下:i 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2W[i] 7 9 10 5 8 4 2 1 6 3 7 9 10 5 8 4 2RESULT 0 1 2 3 4 5 6 7 8 9 10校验码A[1] 1 0 X 9 8 7 6 5 4 3 2*/public static boolean idCardValidate(String idCard) {String[] valCodeArr = {"1", "0", "x", "9", "8", "7", "6", "5", "4", "3", "2"};String[] wi = {"7", "9", "10", "5", "8", "4", "2", "1", "6", "3", "7", "9", "10", "5", "8", "4", "2"};String ai = "";String ai1 = "";String ai2 = "";// 号码的长度 15位或18位if (idCard.length() != 15 && idCard.length() != 18) {return false;}// 数字除最后以为都为数字if (idCard.length() == 18) {ai = idCard.substring(0, 17);} else if (idCard.length() == 15) {ai = idCard.substring(0, 6) + "19" + idCard.substring(6, 15);}if (!isNumeric(ai)) {return false;}// 出⽣年⽉是否有效String strYear = ai.substring(6, 10); // 年份String strMonth = ai.substring(10, 12); // ⽉份String strDay = ai.substring(12, 14); // ⽉份if (!isDataFormat(strYear + "-" + strMonth + "-" + strDay)) {return false;}GregorianCalendar gc = new GregorianCalendar();SimpleDateFormat s = new SimpleDateFormat("yyyy-MM-dd");try {if ((gc.get(Calendar.YEAR) - Integer.parseInt(strYear)) > 150|| (gc.getTime().getTime() - s.parse(strYear + "-" + strMonth + "-" + strDay).getTime()) < 0) {return false;}} catch (Exception e) {e.printStackTrace();}if (Integer.parseInt(strMonth) > 12 || Integer.parseInt(strMonth) == 0) {return false;}if (Integer.parseInt(strDay) > 31 || Integer.parseInt(strDay) == 0) {return false;}// 地区码是否有效Hashtable h = getAreaCode();if (h.get(ai.substring(0, 2)) == null) {return false;}// 判断最后⼀位的值int totalmulAiWi = 0;for (int i = 0; i < 17; i++) {totalmulAiWi = totalmulAiWi + Integer.parseInt(String.valueOf(ai.charAt(i))) * Integer.parseInt(wi[i]);}int modValue = totalmulAiWi % 11;String strVerifyCode = valCodeArr[modValue];ai1 = ai + strVerifyCode.toUpperCase();ai2 = ai + strVerifyCode.toLowerCase();if (idCard.length() == 18) {if (!ai1.equals(idCard) && !ai2.equals(idCard)) {return false;}}return true;}private static boolean isNumeric(String str) {Pattern pattern = pile("[0-9]*");Matcher isNum = pattern.matcher(str);if (isNum.matches()) {return true;}return false;}private static boolean isDataFormat(String str) {boolean flag = false;String regxStr = "^((\\d{2}(([02468][048])|([13579][26]))[\\-\\/\\s]?((((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])))))|(\\d{2}(([02468][1235679])|([135 Pattern pattern1 = pile(regxStr);Matcher isNo = pattern1.matcher(str);if (isNo.matches()) {flag = true;}return flag;}private static Hashtable getAreaCode() { Hashtable hashtable = new Hashtable(); hashtable.put("11", "北京");hashtable.put("12", "天津");hashtable.put("13", "河北");hashtable.put("14", "⼭西");hashtable.put("15", "内蒙古");hashtable.put("21", "辽宁");hashtable.put("22", "吉林");hashtable.put("23", "⿊龙江");hashtable.put("31", "上海");hashtable.put("32", "江苏");hashtable.put("33", "浙江");hashtable.put("34", "安徽");hashtable.put("35", "福建");hashtable.put("36", "江西");hashtable.put("37", "⼭东");hashtable.put("41", "河南");hashtable.put("42", "湖北");hashtable.put("43", "湖南");hashtable.put("44", "⼴东");hashtable.put("45", "⼴西");hashtable.put("46", "海南");hashtable.put("50", "重庆");hashtable.put("51", "四川");hashtable.put("52", "贵州");hashtable.put("53", "云南");hashtable.put("54", "西藏");hashtable.put("61", "陕西");hashtable.put("62", "⽢肃");hashtable.put("63", "青海");hashtable.put("64", "宁夏");hashtable.put("65", "新疆");hashtable.put("71", "台湾");hashtable.put("81", "⾹港");hashtable.put("82", "澳门");hashtable.put("91", "国外");return hashtable;}}。
java课程设计身份证生成和查询系统

郑州航空工业管理学院Java程序设计课程设计题目:身份证生成和查询系统学号:141009117姓名:王创业指导老师:王杰2017 年06 月20日课程设计任务书摘要每个人从出生之后就会有身份证号码,随到达一定的年龄,我们需要去派出所办理属于自己的身份证,身份证也成居民身份证,是用于证明持有人身份的一种法定证件,它将作为每个人独一无二的公民身份的证明工具,本人所做的身份证号自动生成系统是根据输入的家庭住址和出生年日期,性别,通过这些自动生成,所以,第一个功能就是生成,当点击生成按钮后,在生成身份证号后同时将注册的个人信息保存在数据库中。
另一个功能就是查询,输入所产生的身份证号,点击查询按钮后,会将查询者的个人信息输出在界面上,十分快捷,方便。
本系统总共分为5章,第1章讲述了前言概括,第2章系统需求分析,第3章系统概要设计,第4章主要讲述了程序系统的详细实现界面,讲述了系统运行及其调示,第5章作为总结,主要写自己的心得体会及做课题当中所遇到的问题,及解决办法。
该系统编程语言使用Java语言,开发工具为My Eclipse,数据库采用mysql。
关键词:查询;唯一;快捷目录摘要 (1)第1章前言 (3)1.1设计目的 (3)1.2设计背景 (3)第2章需求分析 (4)2.1起源 (4)2.2趋势 (4)第3章系统设计 (5)3.1系统目标 (5)3.2系统功能结构 (5)3.3数据库设计 (6)第4章系统实现 (7)4.1主窗体设计 (7)4.2错误提示 (8)4.3生成界面 (8)4.4生成界面 (9)4.5重点部分代码 (10)第5章结束语 (11)参考文献 (12)第1章前言自1946年第一台计算机问世以来,计算机产业的飞速发展已远远超出人们对它的预料,在某些生产线上,甚至一秒钟就能生产出一台微型计算机,产量猛增,价格低廉,这就使得它的应用范围迅速扩展。
如今,计算机已深入到人类社会的各个领域。
各种应用程序不断地被开发应用,随之程序设计语言也不断发展完善,Java便是这程序语言世界里的一朵奇葩,如今甚为流行。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
java验证身份证号码及编码规则和提取相应信息/** * 将15位的身份证转成18位身份证* * @param idcard * @return */ public String convertIdcarBy15bit(String idcard){ String idcard17 = null; // 非15位身份证if (idcard.length() != 15){ return null; } if (isDigital(idcard)) { // 获取出生年月日String birthday = idcard.substring(6, 12);Date birthdate = null; try{ birthdate = new SimpleDateFormat("yyMMdd").parse(birthday);} catch (ParseException e){ e.printStackTrace();} Calendar cday =Calendar.getInstance();cday.setTime(birthdate); String year = String.valueOf(cday.get(Calendar.YEAR));idcard17 = idcard.substring(0, 6) + year +idcard.substring(8); char c[] =idcard17.toCharArray(); StringcheckCode = ""; if (null != c){ int bit[] = new int[idcard17.length()]; // 将字符数组转为整型数组bit = converCharToInt(c); int sum17 = 0; sum17 = getPowerSum(bit); // 获取和值与11取模得到余数进行校验码checkCode = getCheckCodeBySum(sum17);// 获取不到校验位if (null == checkCode) { returnnull; } // 将前17位与第18位校验码拼接idcard17 += checkCode; } } else { //身份证包含数字return null; } return idcard17; } /** * 15位和18位身份证号码的基本数字和位数验校* * @param idcard * @return */ public boolean isIdcard(String idcard) { return idcard == null || "".equals(idcard) ? false :Pattern.matches( "(^\\d{15}$)|(\\d{17 }(?:\\d|x|X)$)", idcard); } /** * 15位身份证号码的基本数字和位数验校* * @param idcard * @return */ publicboolean is15Idcard(String idcard) { return idcard == null || "".equals(idcard) ? false :Pattern.matches( "^[1-9]\\d{7}((0\\d)| (1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}$",idcard); } /** * 18位身份证号码的基本数字和位数验校* * @param idcard * @return */ public booleanis18Idcard(String idcard) { returnPattern .matches("^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{ 3}([\\d|x|X]{1})$",idcard); } /** * 数字验证* * @param str * @return */ public boolean isDigital(String str) { return str == null || "".equals(str) ? false :str.matches("^[0-9]*$"); } /** * 将身份证的每位和对应位的加权因子相乘之后,再得到和值* * @param bit * @return */ public int getPowerSum(int[] bit) { int sum = 0; if (power.length != bit.length) { return sum; } for (int i = 0; i <bit.length; i++) { for (int j = 0; j < power.length; j++) { if (i == j){ sum = sum + bit[i] *power[j]; } } } return sum; } /*** 将和值与11取模得到余数进行校验码判断** @param checkCode * @param sum17 * @return 校验位*/ public String getCheckCodeBySum(int sum17) { String checkCode = null; switch (sum17 % 11){ case 10: checkCode = "2"; break; case 9: checkCode = "3"; break; case 8: checkCode = "4"; break;case 7: checkCode = "5";break; case 6: checkCode = "6"; break; case 5: checkCode = "7"; break;case 4: checkCode = "8";break; case 3: checkCode = "9"; break; case 2: checkCode = "x"; break;case 1: checkCode = "0";break; case 0: checkCode = "1"; break; }return checkCode; } /** * 将字符数组转为整型数组* * @param c* @return * @throws NumberFormatException*/ public int[] converCharToInt(char[] c) throws NumberFormatException { int[] a = newint[c.length]; int k = 0; for (char temp : c) { a[k++] =Integer.parseInt(String.valueOf(temp)); } return a; } public static void main(String[] args) throws Exception { String idcard15 = ""; String idcard18 = ""; IdcardValidator iv = new IdcardValidator();boolean flag = false; flag =iv.isValidate18Idcard(idcard18);System.out.println(flag); flag =iv.isValidate15Idcard(idcard15);System.out.println(flag);System.out.println(iv.convertIdcarBy15bit(idcard15));flag =iv.isValidate18Idcard(iv.convertIdcarBy15bit(idcard15)); System.out.println(flag);System.out.println(iv.isValidatedAllIdcard(idcard18));} } 提取身份证相关信息:IdcardInfoExtractor.java Java代码importjava.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; importjava.util.GregorianCalendar; import java.util.HashMap; import java.util.Map; import java.util.Set; /** * <p> * 类说明:提取身份证相关信息* </p> */ public class IdcardInfoExtractor{ // 省份private String province;// 城市private String city; // 区县private String region; // 年份private int year; // 月份private int month; // 日期private int day; // 性别private String gender; // 出生日期private Date birthday; private Map<String, String> cityCodeMap = new HashMap<String, String>(){ { this.put("11", "北京"); this.put("12", "天津"); this.put("13", "河北"); this.put("14", "山西");this.put("15", "内蒙古"); this.put("21", "辽宁"); this.put("22", "吉林");this.put("23", "黑龙江"); this.put("31", "上海"); this.put("32", "江苏");this.put("33", "浙江"); this.put("34", "安徽"); this.put("35", "福建");this.put("36", "江西"); this.put("37", "山东"); this.put("41", "河南");this.put("42", "湖北"); this.put("43", "湖南"); this.put("44", "广东");this.put("45", "广西"); this.put("46", "海南"); this.put("50", "重庆");this.put("51", "四川"); this.put("52", "贵州"); this.put("53", "云南");this.put("54", "西藏"); this.put("61", "陕西"); this.put("62", "甘肃");this.put("63", "青海"); this.put("64", "宁夏"); this.put("65", "新疆");this.put("71", "台湾"); this.put("81", "香港"); this.put("82", "澳门");this.put("91", "国外"); } };private IdcardValidator validator = null; /*** 通过构造方法初始化各个成员属性*/public IdcardInfoExtractor(String idcard) { try { validator = new IdcardValidator();if (validator.isValidatedAllIdcard(idcard)){ if (idcard.length() == 15){ idcard =validator.convertIdcarBy15bit(idcard);} // 获取省份String provinceId = idcard.substring(0, 2);Set<String> key = this.cityCodeMap.keySet();for (String id : key) { if(id.equals(provinceId)){ this.province =this.cityCodeMap.get(id);break; } } // 获取性别String id17 =idcard.substring(16, 17); if (Integer.parseInt(id17) % 2 != 0){ this.gender = "男"; } else{ this.gender = "女"; } // 获取出生日期String birthday =idcard.substring(6, 14); Date birthdate = newSimpleDateFormat("yyyyMMdd").parse(birthday); this.birthday = birthdate; GregorianCalendar currentDay = new GregorianCalendar();currentDay.setTime(birthdate);this.year = currentDay.get(Calendar.YEAR);this.month = currentDay.get(Calendar.MONTH) + 1; this.day =currentDay.get(Calendar.DAY_OF_MONTH);} } catch (Exception e){ e.printStackTrace(); } } /** * @return the province */ public String getProvince() { return province; } /** * @return the city */ public String getCity() { return city; } /** * @return the region*/ public String getRegion() { return region; } /** * @return the year */ public int getYear() { returnyear; } /** * @return the month */ public int getMonth() { return month; } /** * @return the day*/ public int getDay() { returnday; } /** * @return the gender */ public String getGender() { return gender; } /** * @return the birthday */ public Date getBirthday(){ return birthday; }@Override public String toString(){ return "省份:" + this.province + ",性别:" + this.gender + ",出生日期:" +this.birthday; } public static voidmain(String[] args) { String idcard = ""; IdcardInfoExtractor ie = new IdcardInfoExtractor(idcard); System.out.println(ie.toString()); } }。