Java based on the ID number and the tool class that gets the user's age and gender

Source: Internet
Author: User

Tag:web   text    algorithm    ret   port    fda   parse   ext    validation    

Import Java.text.simpledateformat;import java.util.date;import java.util.hashmap;import java.util.Map;/** * ID information algorithm class * * @author Javaweb * */public class Cardutil {/** * According to the ID number of the current identity card holder's gender and age 18 ID Card * * @return * @throws Exception * * public static map<string, object> Getcarinfo (String cardcode) throws Exception {map<string, object> Map = new H Ashmap<string, object> (); String year = cardcode.substring (6). substring (0, 4);//gets years string Yue = cardcode.substring (Ten). substring (0, 2);//Get month// String day=cardcode.substring (n). substring (0,2);//Get Day string sex;if (Integer.parseint (cardcode.substring (16). SUBSTRING (0, 1))% 2 = = 0) {//judge sex sex = "female";} else {sex = "male";} Date date = new Date (),//Gets the current system time SimpleDateFormat format = new SimpleDateFormat ("Yyyy-mm-dd"); String fyear = Format.format (date). substring (0, 4);//Current year string Fyue = Format.format (date). substring (5, 7);//month//Strin G Fday=format.format (date). substring (8,10); int age = 0;if (Integer.parseint (Yue) <= INTEGER.PARseint (Fyue)) {//the month in which the current month is greater than the user's origin indicates that the age = Integer.parseint (fyear)-integer.parseint (year) + 1;} else {//the current user has not yet been born age = I Nteger.parseint (Fyear)-integer.parseint (year);} Map.put ("Sex", sex); Map.put ("Age", age); return map;  /** * 15-digit ID Verification * * @param * @throws Exception */public static map<string, object> getcarinfo15w (String card) throws Exception {map<string, object> Map = new hashmap<string, object> ();  String uyear = "+" + card.substring (6, 8);//year string Uyue = Card.substring (8, 10);//month//String uday=card.substring (10, 12);//day String usex = card.substring (14, 15);//user's gender string sex;if (Integer.parseint (usex)% 2 = = 0) {sex = "female";} else {SE x = "Male";} Date date = new Date (),//Gets the current system time SimpleDateFormat format = new SimpleDateFormat ("Yyyy-mm-dd"); String fyear = Format.format (date). substring (0, 4);//Current year string Fyue = Format.format (date). substring (5, 7);//month//Strin G Fday=format.format (date). substring (8,10); int age = 0;if (Integer.parseint (Uyue) <= Integer.parseint (Fyue) {//the month in which the current month is greater than the user's origin indicates that the age = Integer.parseint (fyear)-Integer.parseint (uyear) + 1;} else {//the current user has not yet been born age = Integer . parseint (Fyear)-Integer.parseint (uyear); Map.put ("Sex", sex); Map.put ("Age", age); return map;}}

  

Java based on the ID number and the tool class that gets the user's age and gender

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.