Here you can find the source of yearsBetween(final Date startDate, final Date endDate)
public static long yearsBetween(final Date startDate, final Date endDate)
//package com.java2s; //License from project: Apache License import java.util.Calendar; import java.util.Date; public class Main { public static long yearsBetween(final Date startDate, final Date endDate) { return daysBetween(startDate, endDate) / 365l; }/*from w w w . j a v a 2 s. c o m*/ public static long daysBetween(final Calendar startDate, final Calendar endDate) { long days = 0; while (endDate.after(startDate)) { endDate.add(Calendar.DATE, -1); ++days; } return days; } public static long daysBetween(final Date startDate, final Date endDate) { Calendar start = Calendar.getInstance(); Calendar end = Calendar.getInstance(); start.setTime(startDate); end.setTime(endDate); return daysBetween(start, end); } }