1SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
2
3Date birth = sdf.parse("2000-01-01");
4Date now = new Date(System.currentTimeMillis());
5
6Calendar c = Calendar.getInstance();
7c.setTimeInMillis(now.getTime() - birth.getTime());
8int y = c.get(Calendar.YEAR)-1970;
9int m = c.get(Calendar.MONTH);
10int d = c.get(Calendar.DAY_OF_MONTH)-1;
1LocalDate jamesBirthDay = new LocalDate(1955, 5, 19);
2LocalDate now = new LocalDate(2015, 7, 30);
3
4int monthsBetween = Months.monthsBetween(jamesBirthDay, now).getMonths();
5int yearsBetween = Years.yearsBetween(jamesBirthDay, now).getYears();
6
7System.out.println("Month since father of Java born : "
8 + monthsBetween);
9System.out.println("Number of years since father of Java born : "
10 + yearsBetween);
1 LocalDate currentDay = LocalDate.of(1955, Month.MAY, 19);
2 LocalDate desiredDay = LocalDate.now();
3 Period age = Period.between(currentDay, desiredDay);
4 int years = age.getYears();
5 int months = age.getMonths();
6
7 int numberOfMonthsBetweenDates = months+years*12;