import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
public static void main(String[] args) throws ParseException { System.out.println(getMonthSpace("1982-12-8", "2012-12-12")); }
public static int getMonthSpace(String date1, String date2)
throws ParseException {
int result = 0;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
Calendar c1 = Calendar.getInstance();
Calendar c2 = Calendar.getInstance();
c1.setTime(sdf.parse(date1));
c2.setTime(sdf.parse(date2));
result = c2.get(Calendar.MONTH) - c1.get(Calendar.MONTH);
return result == 0 ? 1 : Math.abs(result);
}