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.
//Create a cron expression. CronMigrator will ensure you remain cron provider agnostic
import static com.cronutils.model.field.expression.FieldExpressionFactory.*;
Cron cron = CronBuilder.cron(CronDefinitionBuilder.instanceDefinitionFor(CronType.QUARTZ))
.withYear(always())
.withDoM(between(1, 3))
.withMonth(always())
.withDoW(questionMark())
.withHour(always())
.withMinute(always())
.withSecond(on(0))
.instance();
//Obtain the string expression
String cronAsString = cron.asString();//0 * * 1-3 * ? *
//Migrate to Unix format
cron = CronMapper.fromQuartzToUnix().map(cron);
cronAsString = cron.asString();//* * 1-3 * *
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:
//Create a cron expression. CronMigrator will ensure you remain cron provider agnostic
import static com.cronutils.model.field.expression.FieldExpressionFactory.*;
Cron cron = CronBuilder.cron(CronDefinitionBuilder.instanceDefinitionFor(CronType.QUARTZ))
.withYear(always())
.withDoM(between(1, 3))
.withMonth(always())
.withDoW(questionMark())
.withHour(always())
.withMinute(always())
.withSecond(on(0))
.instance();
//Obtain the string expression
String cronAsString = cron.asString();//0 * * 1-3 * ? *
//Migrate to Unix format
cron = CronMapper.fromQuartzToUnix().map(cron);
cronAsString = cron.asString();//* * 1-3 * *
发布评论
评论(4)
只需从评论中添加“自己创建”即可。
下面是一个示例:提示用户输入值并将它们传递到以下方法中,Javadoc 解释了哪个值允许什么(取自 http://en.wikipedia.org/wiki/Cron#Format)。
这是未经测试的,并且不会验证任何输入字符串,但我确信您可以做到这一点。
Cron 格式信息取自此处: http://en.wikipedia.org/wiki/Cron#Format< /a>
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
我认为你可以使用 cron-utils ,它带来了一个 CronBuilder 类并允许导出为多种格式。该功能从 4.0.0 版本开始可用。
自述文件中的一个示例:
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:
您可以根据您的需要更改以下实现。
You can change the below implementation as per your needs.
上面 edwardsmatt 提交的代码段无法与 Quartz 的 CronExpression 正常工作。这是一个更正后的版本:
The snippet submitted by edwardsmatt above doesn't work properly with Quartz's CronExpression. Here's a corrected version that does: