身份证号解析,demo
/** * 身份证号解析demo * */ public class TestArea { public static void main(String[] args) { System.out.println("测试"); // 需求:身份证号码,地区号+生日:年+月+日+性别 String cardNo = "61011320010505241X"; String area = ""; // 前6位,国家标准(国标GB) // 截串,身份证18位,固有长度 area = cardNo.substring(0, 6); System.out.println("区域编码:" + area); String birthday = ""; birthday = cardNo.substring(6, 14); System.out.println("出生年月:" + birthday); int year; // 从中间变量birthday来截取 year = Integer.parseInt(birthday.substring(0, 4)); // 字符串转成整数 System.out.println(year); int month; System.out.println(birthday.substring(4, 6)); month = Integer.parseInt(birthday.substring(4, 6)); System.out.println(month); int day; day = Integer.parseInt(birthday.substring(6)); System.out.println(day); System.out.println("" + year + month + day); System.out.println("生日:"+year + "年" + month + "月" + day + "日"); //倒数第二位 String sex = ""; sex = cardNo.substring( cardNo.length() -2 , cardNo.length() -1); System.out.println(sex); } }