Here you can find the source of getMonthCount(Date startDate, Date endDate)
Parameter | Description |
---|---|
startDate | bounds start |
endDate | bounds end |
public static int getMonthCount(Date startDate, Date endDate)
//package com.java2s; import java.util.Calendar; import java.util.Date; public class Main { /**//from w w w .j av a2 s. c o m * Return month count. * * @param startDate bounds start * @param endDate bounds end * @return count of months. (if start month == end month, count = 1) */ public static int getMonthCount(Date startDate, Date endDate) { int count = 1; Calendar calendar = Calendar.getInstance(); calendar.setTime(endDate); count += calendar.get(Calendar.YEAR) * 12 + calendar.get(Calendar.MONTH); calendar.setTime(startDate); count -= calendar.get(Calendar.YEAR) * 12 + calendar.get(Calendar.MONTH); return count; } }