Here you can find the source of getMonthOffset(Date sourceDate, Date targetDate)
public static int getMonthOffset(Date sourceDate, Date targetDate)
//package com.java2s; //License from project: Apache License import java.util.*; public class Main { public static int getMonthOffset(Date sourceDate, Date targetDate) { int sourceMonth = getMonth(sourceDate); int sourceYear = getYear(sourceDate); int targetMonth = getMonth(targetDate); int targetYear = getYear(targetDate); return (sourceYear - targetYear) * 12 + sourceMonth - targetMonth; }/*from ww w. j a v a 2 s . com*/ public static int getMonth(Date date) { java.util.Calendar c = java.util.Calendar.getInstance(); c.setTime(date); return c.get(java.util.Calendar.MONTH) + 1; } public static int getYear(Date date) { java.util.Calendar c = java.util.Calendar.getInstance(); c.setTime(date); return c.get(java.util.Calendar.YEAR); } }