This is what I did, but it did not take into account the leap years
public static int calculateAge(String yyyyMMddBirthDate){
DateTimeFormat fmt = DateTimeFormat.getFormat("yyyy-MM-dd");
Date birthDateDate = fmt.parse(yyyyMMddBirthDate);
Date nowDate=new Date();
long differenceInMillis=nowDate.getTime()-birthDateDate.getTime();
int days=(int)Math.abs(differenceInMillis/(1000*60*60*24));
int ages=(int)days/365;
System.out.println(days+" days");
return ages;
}
I heard we have to use Joda time to calculate ages, but seem GWT does not support Joda time.
Can we just simply use simple code to calculate ages in GWT rather than using library?
Note: This is GWT question, not Java one. The GWT does not support java.text or Joda.