/* There is no big function or security verification, but the length of the entered ID card number is verified.
You can add other functions by yourself. */
Import java. util. *; import java. util. imports; import java. text. *; import java. util. date; class Test02 {public static void main (String [] args) {custom input = new partition (System. in); System. out. println ("Enter your ID number:"); String s = input. next (); while (s. length ()! = 18) // determine the number of inputs to preliminarily verify the authenticity of the ID card number {System. out. println ("your input is incorrect. Please enter it again! "); S = input. next () ;}// read the information using the substring method of String [] String yy1 = s. substring (6, 10); // The Year of birth String mm1 = s. substring (); // The month of birth String dd1 = s. substring (); // Date of Birth: System. out. println ("your birthday is:"); String birthday = yy1.concat ("-"). concat (mm1 ). concat ("-"). concat (dd1); // replace the 0 System in the string with replace. out. println (mm1.replace ("0", "") + "month" + dd1.replace ("0", "") + "); System. out. println ("Your Date of Birth:"); System. out. println (birthday); // calculate the age. try {Date date = new Date (); SimpleDateFormat sdf = new SimpleDateFormat ("yyy-MM-dd"); String s1 = sdf. format (date); Date today = sdf. parse (s1 );
/* The parse method can be used to query the api by yourself. It converts the document (here it is String) format to the sdf (custom Date Format ). */
Date birth = sdf. parse (birthday); System. out. println ("your age:"); System. out. println (today. getYear ()-birth. getYear (); // System. out. println (today); // System. out. println (today. getYear ();} catch (Exception e) {System. out. println ("a problem has happened! ");} System. out. println (" Thank you! ");}}
// Exception handling is performed here due to version issues