您的位置:首页 > 其它

身份证信息如何提取出生年月?

2018-02-27 15:24 218 查看
1.身份证提起出生年月信息

注意:有15位和18位

public String idCard2Birthday(String no) {
String birthday = "";
if (no.length() == 15) {
String tempYear = no.substring(6, 8);
String tempMonth = no.substring(8, 10);
String tempDate = no.substring(10, 12);

int tempCYear = Calendar.getInstance().get(Calendar.YEAR);
tempYear = "20" + tempYear;
int itempYear = Integer.parseInt(tempYear);
if (itempYear > tempCYear) {
tempYear = "19" + tempYear.substring(2);
}
birthday = tempYear + "-" + tempMonth + "-" + tempDate;
} else if (no.length() == 18) {
String tempYear = no.substring(6, 10);
String tempMonth = no.substring(10, 12);
String tempDate = no.substring(12, 14);
birthday = tempYear + "-" + tempMonth + "-" + tempDate;
}
return birthday;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: