Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
public static void main(String[] args) {
CronDefinition cronDefinition = CronDefinitionBuilder.instanceDefinitionFor(QUARTZ);
CronParser parser = new CronParser(cronDefinition);
Cron quartzCron = parser.parse("0 23 * ? * 1-5 *");
ExecutionTime executionTime = ExecutionTime.forCron(quartzCron);
ZonedDateTime lastExecution = ZonedDateTime.ofInstant(new Date().toInstant(), ZoneId.systemDefault());
Optional<ZonedDateTime> lastExec = executionTime.lastExecution(lastExecution);
ZonedDateTime now = ZonedDateTime.now();
final long millis = executionTime.timeToNextExecution(now).get().toMillis();
System.out.println(String.format("last: %s - millis: %s", lastExec, millis));
}
/* Execution should give a similar result:
last: Optional[2019-02-12T13:23+01:00[XXXX/yyyyyyyyyyy]] - millis: 1404328
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment