fix: 健康管理,自测问题修复。

This commit is contained in:
tianyongbao
2024-12-08 01:24:34 +08:00
parent 4db3d2dcc8
commit a885b707a7

View File

@@ -233,12 +233,17 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
// 方法三使用Calendar类计算年龄差距
int ageInYears = currentDate.get(Calendar.YEAR) - birthdayDate.get(Calendar.YEAR);
int ageInMonths = currentDate.get(Calendar.MONTH) - birthdayDate.get(Calendar.MONTH);
if (birthdayDate.get(Calendar.MONTH) > currentDate.get(Calendar.MONTH) ||
(birthdayDate.get(Calendar.MONTH) == currentDate.get(Calendar.MONTH)
&& birthdayDate.get(Calendar.DATE) > currentDate.get(Calendar.DATE))) {
ageInYears--;
}
return ageInYears + "周岁";
if(ageInMonths<0){
ageInMonths+=12;
}
return ageInYears + "周岁"+ageInMonths+"";
}