String idCard = patientBound.getIdCard();
String birthdayString;
if (idCard.length() == 18) {
birthdayString = idCard.substring(6, 14);
} else { // 假设是15位身份证号码,并且出生年份是20世纪
birthdayString = "19" + idCard.substring(6, 12);
}
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
LocalDate birthday = LocalDate.parse(birthdayString, formatter);
LocalDate today = LocalDate.now();
int i = today.getYear() - birthday.getYear() - (today.getDayOfYear() < birthday.getDayOfYear() ? 1 : 0);
根据身份证计算年龄
最新推荐文章于 2024-10-27 19:55:47 发布