zoukankan      html  css  js  c++  java
  • Java怎样实现解析身份证号

    身份证号解析,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);
    
    	}
    }
    

      

  • 相关阅读:
    Python 字符串和list的功能翻译
    python .strip()
    python 查看对象功能
    python 字典
    洛谷 P1144 最短路计数 Label:水
    心疼自己,再见
    初赛复习 //附复习资料
    51Nod 1079 中国剩余定理 Label:数论
    转载 乘法逆元
    51Nod 1136 欧拉函数 Label:数论
  • 原文地址:https://www.cnblogs.com/lvxisha/p/11585343.html
Copyright © 2011-2022 走看看