A Java library to parse, validate, migrate crons as well as get human readable descriptions for them. The project follows the Semantic Versioning Convention and uses Apache 2.0 license
cron-utils is available on Maven central repository.
<dependency> <groupId>com.cronutils</groupId> <artifactId>cron-utils</artifactId> <version>9.2.0</version> </dependency>
- Create arbitrary cron expressions: you can define your own cron format! Supported fields are: second, minute, hour, day of month, month, day of week, year.
- You can flag last field as optional!
- Supports all cron special characters: * / , -
- Non-standard characters L, W, # are supported as well!
- Question mark (?) is currently replaced for an asterisk (*). Enhanced support will be provided in a future.
- Print to locale specific human readable format (English, Dutch, French, Italian, Portuguese, Russian and Spanish so far...).
- Parse and Description process are decoupled: parse once and operate with the result!
- Validate if cron string expressions match a cron definition using CronValidator
- Convert crons between different cron definitions: if you need to migrate expressions, CronMapper may help you!
- Pre-defined definitions for the following cron libraries are provided:
//get a predefined instance CronDefinition cronDefinition = CronDefinitionBuilder.instanceDefinitionFor(QUARTZ); //create a parser based on provided definition CronParser parser = new CronParser(cronDefinition); Cron quartzCron = parser.parse("0 * * 1-3 * ? *"); //create a descriptor for a specific Locale CronDescriptor descriptor = CronDescriptor.instance(Locale.UK); //parse some expression and ask descriptor for description String description = descriptor.describe(parser.parse("*/45 * * * * ?")); //description will be: "every 45 seconds" //validate expression quartzCron.validate()
For more examples, check our README and our examples repo
For stats about the project, you can visit our OpenHUB profile
- htime: a Java library to make it easy for humans format a date. You no longer need to remember date time formatting chars: just write an example, and you will get the appropiate formatter.
- cron-utils-spring: a Java library to describe cron expressions in human readable language at Spring framework, using cron-utils.