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;
}
本文介绍了一个从中国身份证号码中提取出生年月日信息的方法。针对15位和18位两种不同长度的身份证号,提供了具体的解析算法实现。对于15位身份证号,考虑到其年代特征,特别处理了世纪转换问题。
1919

被折叠的 条评论
为什么被折叠?



