0

Does anybody know of a Java library that you can use to parse cron expressions? I mainly want to give it a cron expressions and have it calculate its next execution time.

Comments
  • 0
    I think Spring has some classes to do this, if I remember correctly. Never used them though
  • 0
    Spring has Spring Cron, I only used their annotations, so I know for a fact they can parse it, but I never messed with the classes myself

    and then there's Quartz Scheduler apparently. This seems to do exactly what you want using the CronExpression class and getNextValidTimeAfter(Date) function
  • 0
  • 0
    No, but what a coincidence, I've just started working on my Cron PR again

       ____

      /____\

      / //ニヽ /ニヽ

     ||/⌒ヽ /⌒ L

     i⌒ (●)  (●) ヽ

     ヽ_       |

       >、___0_ノ

    *Yes I know with 100+ million programmers it isn't that much of a coincidence.*
  • 0
    @Hazarth I did the the SpringCron classes, but I'm not using Spring and I don't want to have the entire framework in there just to use the cron classes, I did look at the Quartz scheduler, but I didn't see the getNextValidTimeAfter method, so I'll probably take another look, thanks!
  • 0
    @daxinator22 I never used it myself. But here is a GitHub permalink to the method: https://github.com/quartz-scheduler...

    You should theoretically be able to either just copy the entire class into your code (it seems to only be dependent on Java classes, so this should work out of the box I think?)

    or you can try getting the library and see if you can find it there. The class is public and everything seems accessible to me. Good luck!
Add Comment