DateUtil { public static boolean checkNMonthLegal(String dateFrom, String dataTo, int monthNumber) { Calendar fromCalendar = Calendar.getInstance(TimeZone.getDefault()); fromCalendar.setTime(DateUtil.dateStr2Date(dateFrom)); Calendar endCalendar = Calendar.getInstance(TimeZone.getDefault()); endCalendar.setTime(DateUtil.dateStr2Date(dataTo)); if (!fromCalendar.after(endCalendar)) { Calendar standardCalendar = Calendar.getInstance(TimeZone.getDefault()); boolean endLegal = !endCalendar.after(standardCalendar); standardCalendar.add(Calendar.MONTH, -monthNumber); boolean startLegal = !standardCalendar.after(fromCalendar); return endLegal && startLegal; } return false; } private  DateUtil(); static String getLastDayStr(); static Date getLastDay(); static String getLastWeekStart(String date); static String getWeekStart(String date); static String getOneMonthAgo(); static String getNDay(int n); static Calendar strToCalendar(String dateStr); static Date dateStr2Date(String str); static Date timeStr2Date(String str); static boolean checkNMonthLegal(String dateFrom, String dataTo, int monthNumber); static boolean checkNowBeforeDate(Date date); static boolean checkNowBeforeDate(String dateStr); static boolean checkDateInterval(String startStr, String endStr, String dataStr); static Date getDelayTime(Date date, int second); static List<Date> getRandomDateList(Date startDate, Date endDate, int count);  }
@Test public void checkNMonthLegal() { String dateFrom = "2018-06-10"; String dateTo = "2018-07-09"; System.out.println("checkNMonthLegal result：" + DateUtil.checkNMonthLegal(dateFrom, dateTo, 2)); }