Here you can find the source of countDiffMonth(Calendar cBegin, Calendar cEnd, boolean isRoundUp)
public static int countDiffMonth(Calendar cBegin, Calendar cEnd, boolean isRoundUp)
//package com.java2s; /*// w w w.j a va2 s . c o m * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ import java.util.Calendar; public class Main { public static int countDiffMonth(Calendar cBegin, Calendar cEnd, boolean isRoundUp) { int diffMonth = 0; int dBegin = 0; int dEnd = 0; int mBegin = 0; int mEnd = 0; try { dBegin = cBegin.get(Calendar.DATE); dEnd = cEnd.get(Calendar.DATE); mBegin = (cBegin.get(Calendar.YEAR) * 12) + cBegin.get(Calendar.MONTH); mEnd = (cEnd.get(Calendar.YEAR) * 12) + cEnd.get(Calendar.MONTH); diffMonth = mEnd - mBegin; if (!isRoundUp) { return diffMonth; } if (dEnd > dBegin) { if (diffMonth >= 0) { diffMonth++; } else { diffMonth--; } } return diffMonth; } finally { } } }