年龄修改

This commit is contained in:
马三炮 2025-07-07 10:53:29 +08:00
parent 10d83ecac4
commit 49dc4d3130
1 changed files with 7 additions and 2 deletions

View File

@ -745,9 +745,9 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
// 若还未到今年生日年龄减1
int age = period.getYears();
if (now.isBefore(birthDate.withYear(now.getYear()))) {
/* if (now.isBefore(birthDate.withYear(now.getYear()))) {
age--;
}
}*/
return Math.max(age, 0); // 防止负数如未来日期
} catch (DateTimeParseException | IndexOutOfBoundsException e) {
@ -755,6 +755,11 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
}
}
public static void main(String[] args) {
String id = "513127199410222247";
System.out.println("实际年龄"+calculateAge(id));
}
/**
* 身份证脱敏处理
* 保留前6位和后4位中间用*替代