@Test public void testGetCycleFireDate() throws ParseException { String hourCrontab = "0 0 2-22/2 * * ? *"; CronExpression cronExpression = CrontabUtil.parseCronExp(hourCrontab); Date startTime = new Date(1495555200000L); Date endTime = new Date(1495814400000L); List<Date> dateList = CrontabUtil.getCycleFireDate(startTime, endTime, cronExpression); for (Date date : dateList) { System.out.println(date); } }
public static List<Date> getCycleFireDate(Date startTime, Date endTime, CronExpression cronExpression) { List<Date> dateList = new ArrayList<>(); while (true) { startTime = cronExpression.getNextValidTimeAfter(startTime); if (startTime.after(endTime)) { break; } dateList.add(startTime); } return dateList; }
CrontabUtil { public static List<Date> getCycleFireDate(Date startTime, Date endTime, CronExpression cronExpression) { List<Date> dateList = new ArrayList<>(); while (true) { startTime = cronExpression.getNextValidTimeAfter(startTime); if (startTime.after(endTime)) { break; } dateList.add(startTime); } return dateList; } }
CrontabUtil { public static List<Date> getCycleFireDate(Date startTime, Date endTime, CronExpression cronExpression) { List<Date> dateList = new ArrayList<>(); while (true) { startTime = cronExpression.getNextValidTimeAfter(startTime); if (startTime.after(endTime)) { break; } dateList.add(startTime); } return dateList; }  }
CrontabUtil { public static List<Date> getCycleFireDate(Date startTime, Date endTime, CronExpression cronExpression) { List<Date> dateList = new ArrayList<>(); while (true) { startTime = cronExpression.getNextValidTimeAfter(startTime); if (startTime.after(endTime)) { break; } dateList.add(startTime); } return dateList; }  static Cron parseCron(String crontab); static CronExpression parseCronExp(String crontab); static ScheduleType getCycle(Cron cron); static ScheduleType getCycle(String crontab); static List<Date> getCycleFireDate(Date startTime, Date endTime, CronExpression cronExpression); static ZonedDateTime parseDateToZdt(Date date); static Date parseZdtToDate(ZonedDateTime zdt); static Map.Entry<Date, Date> getPreCycleDate(Date scheduledFireTime, ScheduleType scheduleType); }
CrontabUtil { public static List<Date> getCycleFireDate(Date startTime, Date endTime, CronExpression cronExpression) { List<Date> dateList = new ArrayList<>(); while (true) { startTime = cronExpression.getNextValidTimeAfter(startTime); if (startTime.after(endTime)) { break; } dateList.add(startTime); } return dateList; }  static Cron parseCron(String crontab); static CronExpression parseCronExp(String crontab); static ScheduleType getCycle(Cron cron); static ScheduleType getCycle(String crontab); static List<Date> getCycleFireDate(Date startTime, Date endTime, CronExpression cronExpression); static ZonedDateTime parseDateToZdt(Date date); static Date parseZdtToDate(ZonedDateTime zdt); static Map.Entry<Date, Date> getPreCycleDate(Date scheduledFireTime, ScheduleType scheduleType);  }