判断时间
private boolean canTheTimeExecute() {
try {
if (StringUtils.isEmpty(containerStockSyncTime)) {
log.info("[handleContainerStockSyncTask]-execute time is empty。");
return false;
}
//配置中心按照分钟设置,这里转换成秒格式
String dataTime = containerStockSyncTime + ":00";
LocalTime time = LocalTime.parse(dataTime, DateTimeFormatter.ofPattern("HH:mm:ss"));
String cronStr = time.format(DateTimeFormatter.ofPattern("ss mm HH * * ?"));
if (StringUtils.isEmpty(cronStr)) {
return false;
}
//获取定时器这次执行的时间
List<Date> execTimes = CronPatternUtil.matchedDates(cronStr, DateUtil.beginOfMinute(new Date()), 1, true);
if (CollectionUtils.isEmpty(execTimes)) {
return false;
}
// 判断是否已经到了应该可以执行的时间(分钟未单位)
return (System.currentTimeMillis() - execTimes.get(0).getTime()) >= 0;
} catch (Exception ex) {
log.error("[handleContainerStockSyncTask]- time parse error。", ex);
}
return false;
}
标签:判断,return,java,isEmpty,当前,time,false,execTimes,cronStr
From: https://www.cnblogs.com/daleyzou/p/17995390/getExecuteTime