Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cron expression parsing into java date

  • my database having 10 18 16 ? * SUN,MON,WED,FRI * cron expression then how to convert into Java date.
  • how to comparing with present day time.
  • and one more is how to compare to cron expressions i.e. 10 18 16 ? * SUN,MON,WED,FRI * and 0 30 9 30 * ?
  • please explain the sample code using quartz or spring scheduling.
like image 602
user3599212 Avatar asked May 23 '14 17:05

user3599212


People also ask

What does 0 * * * * mean in crontab?

0 * * * * -this means the cron will run always when the minutes are 0 (so hourly) 0 1 * * * - this means the cron will run always at 1 o'clock. * 1 * * * - this means the cron will run each minute when the hour is 1.

What is cron expression in Java?

A cron expression is a string consisting of six or seven subexpressions (fields) that describe individual details of the schedule. These fields, separated by white space, can contain any of the allowed values with various combinations of the allowed characters for that field.

Is cron expression in UTC?

io's cron expression feature, the designated time zone is UTC. Each field has a set of allowed values, which are the only values that are valid to use for that particular field.


1 Answers

I wrote a small class for handling cron expressions, available here: https://github.com/frode-carlsen/cron

Based on Joda-time, but should be fairly easy to port to Java8 time api. This also makes it possible to embed in unit tests, do simulations etc by adjusting the DateTime offset in Joda-time.

It also has pretty good test coverage (was done as TDD Kata).

Update Now supports java 8 time api as well thanks to a contribution from github user https://github.com/zemiak. In both cases, the expression parser is a single, tiny class which can easily be copied into your own project.

like image 107
f.carlsen Avatar answered Sep 18 '22 19:09

f.carlsen