I need a Java code to create a cron expression based on user inputs. User inputs are Time, frequency and number of executions.
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
The snippet submitted by edwardsmatt above doesn't work properly with Quartz's CronExpression. Here's a corrected version that does:
You can change the below implementation as per your needs.
I think you can use cron-utils, which brings a CronBuilder class and allows to export to multiple formats. The feature is available from version 4.0.0 onwards.
An example from the README:
Just adding on from the comment that says create it yourself.
Here is an example: Prompt the user for the values and pass them into the following method, the Javadoc explains what is allowed in which value (taken from http://en.wikipedia.org/wiki/Cron#Format).
This is untested and doesn't validate any of the input strings, but I'm sure you can do that.
Cron Format Information taken from here: http://en.wikipedia.org/wiki/Cron#Format