Cron 表达式: 之间到底有什么区别?和 * 在 cron 表达式中?

Cron Expression: What exactly is the difference between ? and * in a cron expression?

在我看来都是"any of the available values"的意思。它们之间到底有什么区别?

来自Quartz Scheduler

* ("all values") - used to select all values within a field. For example, "*" in the minute field means "every minute".

? ("no specific value") - useful when you need to specify something in one of the two fields in which the character is allowed, but not the other. For example, if I want my trigger to fire on a particular day of the month (say, the 10th), but don't care what day of the week that happens to be, I would put "10" in the day-of-month field, and "?" in the day-of-week field. See the examples below for clarification.

*字符用于指定所有值。例如,分钟字段中的“*”表示“每分钟”。

? 字符可用于日期和星期字段。它用于指定 'no specific value'。当您需要在两个字段之一而不是另一个字段中指定某些内容时,这很有用。请参阅下面的示例进行说明。

您可以在这里查看更多内容: http://docs.netkernel.org/book/view/book:mod:cron/doc:mod:cron:cronexpression

此外,如果您需要创建一个 Cron 表达式,您可以使用这个:http://www.cronmaker.com/

* 表示字段中所有可能的值。 ? 表示您不关心该值。当您有两个可能相互矛盾的字段时使用它。常见的例子是月中的第几天和星期几字段。例如,考虑每月第一天上午 10 点 运行ning 的 cron 规范:

0 0 10 1 * ? *

现在让我们分解一下:

  • 秒:0 - 我们希望它在 10:00 上 运行:00
  • 分钟:0 - 我们希望它在 10 点 运行:00:00
  • 营业时间:10 - 我们希望 运行 在 10:00:00
  • 一个月中的第几天:1 - 我们希望它是每月 1 号的 运行
  • 月份:* - 我们希望它 运行 每个月(例如,1 月 1 日、2 月 1 日等)
  • 星期几:? - 我们不关心星期几。 cron 应该 运行 在每个月的 1 日,无论是星期天、星期一等
  • 年份:* - 我们希望每年 运行