Musaddique S
Musaddique S

Reputation: 1567

Unable to generate the cron expression using cron-utils

I am using cron-utils jar for generating cron expression

0 0 8 ? 1/1 5#3 *

3rd Thursday of every month at 8 o' clock

Below is my code for above expression:

CronBuilder withMonth = CronBuilder.cron(
      CronDefinitionBuilder.instanceDefinitionFor(CronType.QUARTZ)
).withYear(always()).withDoM(QuestionMark.questionMark())
.withMonth(on(3, SpecialChar.HASH));

withMonth.withDoW(on(5)).withHour(on(8)).withMinute(on(0)).withSecond(on(0));
    
Cron instance = withMonth.instance();
System.out.println(instance.asString());

But I'm getting the following exception:

value missing for a#b cron expression

Upvotes: 1

Views: 703

Answers (1)

Musaddique S
Musaddique S

Reputation: 1567

finally found solution

.withDoW(on(NUM_DAY_WEEK,SpecialChar.HASH, NUM_DAY_MONTH);

it will generate like 5#3

Upvotes: 1

Related Questions