I am using cron-utils jar for generating cron expression like:
0 0 0 ? * 1,3,7 *
At 00:00:00am, on every Sunday, Tuesday and Saturday, every month
How can i create the 'days of week' expression so it will be list and not only one value?
Below is my code for above expression:
CronDefinition definition = CronDefinitionBuilder.instanceDefinitionFor(CronType.QUARTZ);
CronBuilder cronBuilder = CronBuilder.cron(definition)
.withYear(always())
.withMonth(always())
.withDoM(questionMark())
.withHour(on(0))
.withMinute(on(0))
.withSecond(on(0))
.withDoW(on(???????);
You can use and()
and you will be able to pass multiple days.
Example:
CronDefinition definition = CronDefinitionBuilder.instanceDefinitionFor(CronType.QUARTZ);
CronBuilder cronBuilder = CronBuilder.cron(definition)
.withYear(always())
.withMonth(always())
.withDoM(questionMark())
.withHour(on(0))
.withMinute(on(0))
.withSecond(on(0))
.withDoW(on(1).and(on(3)).and(on(5)));