private boolean cronTimeSlot(String startCron, String endCron, Date testTime){
try {
//start
CronExpression cronExpression_start = new CronExpression(startCron);
Date dateStart = cronExpression_start.getNextValidTimeAfter(testTime);
long timeStart = dateStart.getTime();
//end
CronExpression cronExpression_end = new CronExpression(endCron);
Date dateEnd = cronExpression_end.getNextValidTimeAfter(testTime);
long timeEnd = dateEnd.getTime();
//当测试时间点在start和end时间段内时,下次end比下次start早
if (timeEnd < timeStart) {
return true;
}
if(timeEnd > timeStart){
return false;
}
} catch (ParseException e) {
e.printStackTrace();
}
return false;
}
判断时间点是否在Cron表达式时间段内
最新推荐文章于 2024-08-02 13:34:45 发布