Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to create a cron expression for every N hours between time X to time Y #609

Open
elirehema opened this issue Nov 4, 2023 · 0 comments

Comments

@elirehema
Copy link

Hello I was able to create an expression for At 1 minutes past the hour, every 8 hours, between day 1 and 3 of the month, only in 2023

  public static void main(String[] args) {
        CronBuilder builder = CronBuilder.cron(CronDefinitionBuilder.instanceDefinitionFor(CronType.QUARTZ));
        Cron cron = builder
                .withYear(on(2023))
                .withDoM(between(1, 3))
                .withMonth(always())
                .withDoW(questionMark())
                .withHour(every(8))
                .withMinute(on(1))
                .withSecond(on(0))
                .instance();
        System.out.println(cron.asString());
    }

Which produced this output
Screenshot from 2023-11-04 11-37-56

But I wanted to do more by specifying the hours between 06:00 AM to 11:59 PM. Something like this
Screenshot from 2023-11-04 11-37-41
Thanks for any help or suggestion

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant