开发者

how to calculate current age of person from birthdate to current date? [duplicate]

开发者 https://www.devze.com 2023-02-22 20:30 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: How do I calculate someone's age in Java?
This question already has answers here: Closed 11 years ago.

Possible Duplicate:

How do I calculate someone's age in Java?

hi friends

i want to calculate total age of any registered person from birthdate to current date ...i want to count total years and开发者_StackOverflow社区 month and days in between birtdate and current date..

for example=birthdate=8th feb 2008 currentdate=8th april2011 so i want answer is =3 years ,2 months


Here is an example using http://joda-time.sourceforge.net/

import org.joda.time.DateTime;
import org.joda.time.Period;

public class Main{
  public static void main(String[] args) {
      DateTime start = new DateTime(2008, 2, 8, 0, 0, 0, 0);
      DateTime end = new DateTime();
      Period period = new Period(start, end);
      System.out.println(" user is " + period.getYears() + " years " + period.getMonths() + " months old");
  }
}


Have a look at http://joda-time.sourceforge.net/ - it's got a pretty nice API. I was using it the other week to do some work with dates. Hopefully it'll have what you need.

0

精彩评论

暂无评论...
验证码 换一张
取 消