Is there any java libraries which I can use to convert cron expression into time interval? It could be Seconds, Milliseconds, Minutes etc...
Cron Expression (Input): 0/15 * * * * ?
Output1: 15 (getInSeconds)
Output2: 15000 (getInMilliSeconds)
Is there any java libraries which I can use to convert cron expression into time interval? It could be Seconds, Milliseconds, Minutes etc...
Cron Expression (Input): 0/15 * * * * ?
Output1: 15 (getInSeconds)
Output2: 15000 (getInMilliSeconds)
cron-utils does not give you intervals between executions (cron expressions may not have fix-sized time intervals. Example: if executing every first Sunday, time between executions will be contextual to months and years), but provides a method that returns last/next execution as well as Duration from last/next execution given a DateTime.
Here a snippet from the docs:
CronDefinition cronDefinition = CronDefinitionBuilder.instanceDefinitionFor(QUARTZ);
CronParser parser = new CronParser(cronDefinition);
//Get date for last execution
DateTime now = DateTime.now();
ExecutionTime executionTime = ExecutionTime.forCron(parser.parse("* * * * * * *"));
DateTime lastExecution = executionTime.lastExecution(now));
//Get date for next execution
DateTime nextExecution = executionTime.nextExecution(now));
//Time from last execution
Duration timeFromLastExecution = executionTime.timeFromLastExecution(now);
//Time to next execution
Duration timeToNextExecution = executionTime.timeToNextExecution(now);