public boolean checkMonth(String startMonth, String endMonth)
throws Exception {
boolean flag = false;
Calendar c = Calendar.getInstance();// 获得一个日历的实例
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date date = null;
try {
date = sdf.parse(startMonth);// 初始日期
} catch (Exception e) {
throw e;
}
c.setTime(date);// 设置日历时间
c.add(Calendar.MONTH, 2);// 在日历的月份上增加1个月
String realendtime = sdf.format(c.getTime());// 的到你想要得6个月后的日期
endMonth = endMonth.replace("-", "");
realendtime = realendtime.replace("-", "");
startMonth = startMonth.replace("-", "");
// 判断两个月的先后次序和两月之间之差
if ((Integer.parseInt(endMonth) > Integer.parseInt(realendtime))
|| (Integer.parseInt(endMonth) < Integer.parseInt(startMonth))) {
flag = false;
} else {
flag = true;
}
return flag;
}