diff --git a/src/main/java/com/subsidy/util/QuartzUtil.java b/src/main/java/com/subsidy/util/QuartzUtil.java index d60aeca..2ec3f5e 100644 --- a/src/main/java/com/subsidy/util/QuartzUtil.java +++ b/src/main/java/com/subsidy/util/QuartzUtil.java @@ -27,6 +27,10 @@ public class QuartzUtil { @Autowired private Scheduler scheduler; + public static void main(String[] args) { + System.out.println(DateFormatUtil.parse("2022-06-28 11:30:47", "yyyy-MM-dd HH:mm:ss").getTime() -System.currentTimeMillis()); + } + /** * 添加定时任务,只执行一次的定时任务 * @@ -41,7 +45,7 @@ public class QuartzUtil { JobKey key = new JobKey(name, group); List triggers = (List) scheduler.getTriggersOfJob(key); if (triggers.size() == 0) { - int time = (int) (date.getTime() - System.currentTimeMillis()) / 1000; + Long time = (date.getTime() - System.currentTimeMillis()) / 1000; JobDataMap jobDataMap = new JobDataMap(); jobDataMap.put("params", params); JobDetail jobDetail = JobBuilder.newJob(cls) @@ -50,7 +54,7 @@ public class QuartzUtil { .build(); SimpleTrigger trigger = (SimpleTrigger) TriggerBuilder.newTrigger() .withIdentity(name, group) - .startAt(futureDate(time, DateBuilder.IntervalUnit.SECOND)) + .startAt(futureDate(Math.toIntExact(time), DateBuilder.IntervalUnit.SECOND)) .build(); scheduler.scheduleJob(jobDetail, trigger); if (!scheduler.isShutdown()) {