public static int getAge(Date datumDate,Date birthDate){
//datumDate : 结束日期
//birthDate:出生日期
Calendar datumCd = Calendar.getInstance();datumCd.setTime(datumDate);
Calendar birthCd = Calendar.getInstance();
birthCd.setTime(birthDate);
int datumYear = datumCd.get(Calendar.YEAR);
int datumMonth = datumCd.get(Calendar.MONTH);
int datumDay = datumCd.get(Calendar.DAY_OF_MONTH);
int birthYear = birthCd.get(Calendar.YEAR);
int birthMonth = birthCd.get(Calendar.MONTH);
int birthDay = birthCd.get(Calendar.DAY_OF_MONTH);
int result = datumYear - birthYear - 1;
if(datumMonth<birthMonth){
return result;
}
if(datumMonth>birthMonth){
return ++result;
}
if(datumDay>birthDay){
return ++result;
}
return result;
}