Cron 触发时间为 12:04 至 14:25

发布于 2024-08-17 15:59:52 字数 53 浏览 6 评论 0原文

是否可以为必须从 12:04 到 14:25 每天每分钟触发的触发器编写 cron 表达式?

Is it possible to write cron expression for trigger that must fire every day and every minute from 12:04 to 14:25?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

A君 2024-08-24 15:59:52

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

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

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

I think the shortest solution (using cron) are these 3 lines

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

They define the trigger ranges for each hour.

因为看清所以看轻 2024-08-24 15:59:52

您必须设置 3 个 diff cron 作业:

    .---------------- 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>

You'll have to set 3 diff cron jobs:

    .---------------- 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>
帅冕 2024-08-24 15:59:52

您标记了quartz,因此这里是取自文档的示例 http://quartz .sourceforge.net/javadoc/org/quartz/CronTrigger.html

0 * 12-14 * * ? 每天 12:00 到 14:59 之间每分钟触发一次。

从示例来看“0 0/5 14,18 * * ?”从下午 2 点开始到下午 2:55 结束,每 5 分钟触发一次,并且每天从下午 6 点开始到下午 6:55 结束,每 5 分钟触发一次 在我链接到的网页中,您也许可以做一些事情就像

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

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

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

You tagged quartz so here is an example taken from the docs at http://quartz.sourceforge.net/javadoc/org/quartz/CronTrigger.html

0 * 12-14 * * ? would fire every minute every day between 12:00 and 14:59.

Judging by the example "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 in the web page i linked to, you may be able to do something like

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

but I'm not sure that would work because it looks a bit dubious, and the docs don't say how the minutes/hours are interpreted if you write it like that. If it doesn't work, you have to define three triggers:

0 4-59 12 * * ?
0 * 13 * * ?
0 0-25 14 * * ?
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文