1、获取年龄
/**
* @Description 年龄计算 “yyyy-MM-dd” 精确到天
* @param birthDateString 出生日期
* @return 年龄
* @Author syh
* @Date 2024/6/25 16:48
*/
public static int obtainAge(String birthDateString) {
// 假设从输入中获取出生日期
LocalDate birthDate = LocalDate.parse(birthDateString);
// 获取当前日期
LocalDate currentDate = LocalDate.now();
// 计算年龄
Period period = Period.between(birthDate, currentDate);
return period.getYears();
}