Spring boot 如何识别spring中的cron条目在今天是否适用?
我的数据库中有一个cron条目列表,其中只有date、day of month、day of week的值 我的数据库中的示例cron值。 "0 0 * * * " " * * 15 2 " “****周一至周五”Spring boot 如何识别spring中的cron条目在今天是否适用?,spring-boot,cron,Spring Boot,Cron,我的数据库中有一个cron条目列表,其中只有date、day of month、day of week的值 我的数据库中的示例cron值。 "0 0 * * * " " * * 15 2 " “****周一至周五” 我如何检查我的数据库中是否有适用于今天的cron条目?我必须在java spring引导应用程序中使用它。尝试探索cron解析器,它可能会帮助您解决这个问题 You can use cronexpression of quartz to get for next valid fi
我如何检查我的数据库中是否有适用于今天的cron条目?我必须在java spring引导应用程序中使用它。尝试探索cron解析器,它可能会帮助您解决这个问题
You can use cronexpression of quartz to get for next valid fire date of cron.
Ex.
String orgTimeZone = "US/Eastern";
String cron = "0 10 2 ? * MON,WED *";
CronExpression exp = new CronExpression(cron);
exp.setTimeZone(TimeZone.getTimeZone(orgTimeZone));
Date date = new Date();
Date nextValidFireTime = exp.getNextValidTimeAfter(date);
ZonedDateTime nextExecDate = zonedDateTimeConverter.toZonedDateTime(nextValidFireTime, orgTimeZone);
ZonedDateTime currentDate = zonedDateTimeConverter.toZonedDateTime(date, orgTimeZone);
System.out.println(nextExecDate);
ZonedDateTime after1Hourdate = currentDate.plusHours(1);
System.out.println(currentDate + ":" + after1Hourdate);
if (nextExecDate.isAfter(currentDate) && nextExecDate.isBefore(after1Hourdate)) {
System.out.println("Match Cron");
}