Here you can find the source of getMonthDiff(String startDate, String endDate)
public static int getMonthDiff(String startDate, String endDate)
//package com.java2s; public class Main { public static int getMonthDiff(String startDate, String endDate) { String[] startArray = startDate.split("-"); String[] endArray = endDate.split("-"); int startYear = Integer.parseInt(startArray[0]); int startMonth = Integer.parseInt(startArray[1]); int endYear = Integer.parseInt(endArray[0]); int endMonth = Integer.parseInt(endArray[1]); return Math.abs((endYear - startYear) * 12 + endMonth - startMonth); }// w w w .j av a 2 s. c om }