Monday, September 29, 2014

How to calculate ages correctly in GWT?

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?

http://stackoverflow.com/questions/26112354/how-to-calculate-ages-correctly-in-gwt

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment