public static int months(Date start, Date end) {
int count = 0;
Calendar cal = Calendar.getInstance();
cal.setTime(start);
int startDate = cal.get(Calendar.DATE);
int startMonth = cal.get(Calendar.MONTH);
int startYear = cal.get(Calendar.YEAR);
cal.setTime(end);
int endDate = cal.get(Calendar.DATE);
int endMonth = cal.get(Calendar.MONTH);
int endYear = cal.get(Calendar.YEAR);
count = ((endYear - startYear) * 12) + (endMonth - startMonth) + ((endDate >= startDate) ? 1 : 0);
return count - 1;
}
No comments:
Post a Comment