Skip to content

Instantly share code, notes, and snippets.

@ytxmobile98
Created July 17, 2024 02:06
Show Gist options
  • Select an option

  • Save ytxmobile98/e7cc0779c44ce9d156b6cb962baa1330 to your computer and use it in GitHub Desktop.

Select an option

Save ytxmobile98/e7cc0779c44ce9d156b6cb962baa1330 to your computer and use it in GitHub Desktop.
Cron Syntax

Cron 语法

参考链接:

Cron 语法由 5 个字段组成,从左到右分别是:

  1. 分钟(0-59)
  2. 小时(0-23)
  3. 日期(1-31 均有效;如填了 29-31 但是那个月没有那一天,则不会执行该任务)
  4. 月份(1-12)
  5. 星期(0-6,0 表示星期日;或使用缩写:sunmontuewedthufrisat

每个字段可以使用以下的格式:

  • *?:匹配所有值
  • ,:多个值,例如:1,2,3
  • -:范围值,例如:1-3
  • /:步长值,例如:在“分钟”字段填写 0-50/10,表示每隔 10 分钟执行一次

示例

  • 15 14 1 * *:每月 1 日 14:15 执行
  • 0 22 * * 1-5:周一到周五 22:00 执行
  • 23 0-20/2 * * *:每隔 2 小时执行一次,从 0:23 开始,到 20:23 结束
  • 5 4 * * sun:每周日 4:05 执行
  • 0 0,12 1 */2 *:每隔 2 个月的 1 日的 0:00 和 12:00 执行
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment