java输入身份证如何输出年龄?

2022-08-08 教育 71阅读
刚写出来,其实就是字符串的截取。

package com.swing;
import java.util.Calendar;
import java.util.Timer;
public class NianLing {
public static void main(String[] args) {
String s = "610400199011100000";
s = s.substring(6, s.length()-8);
System.out.println(s);
Calendar cal = Calendar.getInstance();
java.util.Date date = cal.getTime();
String s1 = date.toString();
String s2 = (String) s1.subSequence(s1.length()-4, s1.length());
System.out.println(date);
System.out.println(s2);
Integer int1 = Integer.parseInt(s);
Integer int2 = Integer.parseInt(s2);
Integer age = int2-int1;
System.out.println("age : " + age);
}
}

输出结果:age:22
1990
Fri Dec 14 23:26:52 CST 2012
2012
age : 22
声明:你问我答网所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系fangmu6661024@163.com