-
-
Notifications
You must be signed in to change notification settings - Fork 11.3k
Closed
Description
code
@Test
public void testCron() throws Exception {
String cron = "00 00 00 */3 * ? *";
String startTime = "2025-03-31 00:00:00";
int num = 0;
CronExpression cronExpression = new CronExpression(cron);
Date date = DateUtils.localDateTimeToDate(DateUtils.parseMatches(startTime));
Date nextValidTimeAfter = cronExpression.getNextValidTimeAfter(date);
while (Objects.nonNull(nextValidTimeAfter)) {
System.out.println(DateUtils.format(nextValidTimeAfter, DateFormatEnum.YYYY_MM_DD_HH_MM_SS));
nextValidTimeAfter = cronExpression.getNextValidTimeAfter(nextValidTimeAfter);
if (num++ == 30) break;
}
}
printe
2025-04-01 00:00:00
2025-04-04 00:00:00
2025-04-07 00:00:00
........
2025-04-28 00:00:00
2025-05-01 00:00:00
2025-05-04 00:00:00
.........
2025-05-28 00:00:00
2025-05-31 00:00:00
2025-06-01 00:00:00
2025-06-04 00:00:00
..........
每三天执行一次,开始时间为2025-03-31 00:00:00,下次执行时间应该是2025-04-02 00:00:00,输出的下次执行时间为 4月1号
Metadata
Metadata
Assignees
Labels
No labels