Cron从12:04到14:25触发

时间:2010-01-14 13:41:07

标签: triggers cron quartz-scheduler

是否有可能为每天和每分钟从12:04到14:25开火的触发器编写cron表达式?

3 个答案:

答案 0 :(得分:3)

我认为最短的解决方案(使用cron)是这3行

4-59 12 * * * <command>
0-59 13 * * * <command>
0-25 14 * * * <command>

他们定义每小时的触发范围。

答案 1 :(得分:1)

您必须设置3个差异作业:

    .---------------- minute (0 - 59) 
    |  .------------- hour (0 - 23)
    |  |   .---------- day of month (1 - 31)
    |  |   |  .------- month (1 - 12) OR jan,feb,mar,apr ... 
    |  |   |  |  .---- day of week  
    |  |   |  |  |
  4-59 12  *  *  *  <command to be executed>
  0-59 13  *  *  *  <command to be executed>
  0-25 14  *  *  *  <command to be executed>

答案 2 :(得分:1)

您标记了石英,所以这里是从http://quartz.sourceforge.net/javadoc/org/quartz/CronTrigger.html

的文档中获取的示例

0 * 12-14 * * ?每天会在12:00到14:59之间每分钟开火。

根据我链接到的网页中的示例"0 0/5 14,18 * * ?" Fire every 5 minutes starting at 2pm and ending at 2:55pm, AND fire every 5 minutes starting at 6pm and ending at 6:55pm, every day判断,您可以执行类似

的操作

0 4-59,0-59,0-25 12,13,14 * * ?

但是我不确定它是否会起作用,因为它看起来有点可疑,并且如果您这样写的话,文档并没有说明如何解释分钟/小时。如果它不起作用,则必须定义三个触发器:

0 4-59 12 * * ?
0 * 13 * * ?
0 0-25 14 * * ?