@Transient
private int age;
public int getAge() {
Calendar today = Calendar.getInstance();
Calendar date_of_birth = Calendar.getInstance();
date_of_birth.setTime(this.getDateOfBirth());
int diff_year = today.get(Calendar.YEAR) - date_of_birth.get(Calendar.YEAR);
int diff_month = today.get(Calendar.MONTH) - date_of_birth.get(Calendar.MONTH);
int diff_day = today.get(Calendar.DAY_OF_MONTH) - date_of_birth.get(Calendar.DAY_OF_MONTH);
if (diff_month < 0 || (diff_month == 0 && diff_day < 0)) {
diff_year = diff_year - 1; //no aparecían los dos guiones del postincremento :|
}
return diff_year;
}
...entity code...
No hay comentarios:
Publicar un comentario