fix: 健康管理,自测问题修复。
This commit is contained in:
@@ -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+"月";
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user