Cron表达式,从晚上8点到早上6点运行。

huangapple go评论74阅读模式
英文:

Cron expression to run from 8PM to 6 AM

问题

我正在尝试为Spring的@Scheduled注解编写一个cron表达式,该表达式应在晚上8点到早上6点之间每隔10分钟执行一次 -

@Scheduled(cron = "0 */10 20-06 * * MON-FRI", zone = "America/New_York")

然而,上述的cron表达式会引发'Invalid inverted range'异常。当我尝试使用以下表达式时,

@Scheduled(cron = "0 */10 20-23,0-6 * * MON-FRI", zone = "America/New_York")

它在23点到0点之间不会运行。有没有办法编写一个cron表达式,可以涵盖23点到0点的时间段呢?

英文:

I am trying to write a cron expression for spring @Scheduled annotation that should be executed on the interval of 10 minutes between 8 PM to 6 AM -

@Scheduled(cron = "0 */10 20-06 * * MON-FRI", zone = "America/New_York")

However above cron is giving 'Invalid inverted range' exception. When I try

@Scheduled(cron = "0 */10 20-23,0-6 * * MON-FRI", zone = "America/New_York")

then it does not run between 23 and 0.
Is there any way to write a cron expression that can cover 23 to 0 hours also.

答案1

得分: 0

以下是翻译好的部分:

"> 每小时的第10分钟过后,从20点开始,以及每小时从0点到6点,从星期一到星期五的每一天。"

英文:

use below it should run from 8 PM to 6 AM

*/10 20,0-6 * * MON-FRI    (min hour day month week)

above expression translates to -

> At every 10th minute past hour 20 and every hour from 0 through 6 on
> every day-of-week from Monday through Friday

答案2

得分: -1

我会期望你的第二个示例能够工作。不确定这是否是Spring实现中的错误。似乎是这样的。

这非常冗长,但你总是可以枚举整个值列表。

... 20,21,22,23,0,1,2,3,4,5,6 ...

英文:

I would expect your 2nd example to work. Not sure whether that's a bug in Spring's implementation. Seems like it.

It's very long-winded, but you could always just enumerate the entire list of values.

... 20,21,22,23,0,1,2,3,4,5,6 ...

huangapple
  • 本文由 发表于 2020年8月12日 00:35:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/63362563.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定