/**
* 根据生日计算当前周岁数
*/
public static int getCurrentAge(Date birthday) {
DateFormat format1 = new SimpleDateFormat("yyyyMMdd");
Date birthDate3 = new Date();
String end=format1.format(birthDate3);
String birthdayS=format1.format(birthday);
int startYear=Integer.valueOf(birthdayS.substring(0,4));
int endYear=Integer.valueOf(end.substring(0,4));
int year = 0;
if ((endYear - startYear) > 0) {
year = endYear - startYear;
int startMonth = Integer.valueOf(birthdayS.substring(4, 6));
int endYearMonth = Integer.valueOf(end.substring(4, 6));
if (endYearMonth == startMonth) {
int startDate = Integer.valueOf(birthdayS.substring(6, 8));
int endYearDate = Integer.valueOf(end.substring(6, 8));
if (endYearDate < startDate) {
year--;
}
} else if (endYearMonth < startMonth) {
year--;
}
}
return year;
}
java 根据出生日期计算周岁算法.
最新推荐文章于 2023-11-02 17:59:05 发布