Here you can find the source of getMonths(String strDateBegin, String strDateEnd)
public static int getMonths(String strDateBegin, String strDateEnd)
//package com.java2s; public class Main { public static int getMonths(String strDateBegin, String strDateEnd) { try {//from www . ja v a 2s .c o m int strOut; if (strDateBegin.equals("") || strDateEnd.equals("") || strDateBegin.length() != 6 || strDateEnd.length() != 6) { strOut = 0; } else { int intMonthBegin = Integer.parseInt(strDateBegin.substring(0, 4)) * 12 + Integer.parseInt(strDateBegin.substring(4, 6)); int intMonthEnd = Integer.parseInt(strDateEnd.substring(0, 4)) * 12 + Integer.parseInt(strDateEnd.substring(4, 6)); strOut = intMonthEnd - intMonthBegin; } return strOut; } catch (Exception e) { return 0; } } }