package com.jojubanking.boot.module.system.util.xytj;

import java.time.LocalDate;
import java.time.Period;

public class AgeCalculator {
    private String birthDate;

    public AgeCalculator(String birthDate) {
        this.birthDate = birthDate;
    }

    public int calculateAge() {
        // 解析出生日期字符串为LocalDate对象
        LocalDate birthDate = LocalDate.parse(this.birthDate);

        // 计算年龄
        LocalDate currentDate = LocalDate.now();
        Period period = Period.between(birthDate, currentDate);

        return period.getYears();
    }
}
