Cron expressions

Cron expression example:

  • */5 * * * * ?: run every 5 seconds
  • 0 */1 * * * ?: run every 1 minute
  • 0 0 23 * * ?: Execute once a day at 23:00
  • 0 0 1 * * ?: Execute once a day at 1:00 am:
  • 0 0 1 1 * ?: Executed once a month at 1:00 a.m. on the 1st of each month
  • 0 0 23 L * ?: Executed at 23:00 on the last day of every month
  • 0 0 1 ? * L: Executed once a week at 1:00 a.m. on Sundays
  • 0 26,29,33 * * * ?: Execute once at 26 minutes, 29 minutes, and 33 minutes
  • 0 0 0,13,18,21 * * ?: Execute once every day at 0:00, 13:00, 18:00, and 21:00

Cron expressions

The Cron expression consists of 7 parts, and each part is separated by a space. The meanings of the 7 parts of the Cron expression from left to right are as follows:


where is optional.

field name allowed values allowed special characters
0-59 ,- * /
0-59 ,- * /
0-23 ,- * /
1-31 ,- * ? / L W C
1-12 or JAN-DEC ,- * /
1-7 or SUN-SAT ,- * ? / L C #
(optional field) empty,1970-2099 ,- * /

Symbol Description

  • ,: Indicates that enumeration values ​​are listed. For example, when using 5,20, it means triggering every minute at 5 and 20 minutes.
  • -: Indicates the range. For example, when using 5-20, it means to trigger every minute from 5 minutes to 20 minutes.
  • *: Indicates any value matching the field. If used in a domain *, it means that the event will be fired every minute.
  • /: Indicates that the trigger starts at the start time, and then triggers every fixed time. For example, if 5/20 is used in the Minutes field, it means that it triggers once every 5 minutes, and every 25, 45, etc., respectively.
  • ?: can only be used in and . It also matches arbitrary values ​​of the domain, but doesn't actually. Because and will affect each other. For example, if you want to trigger the scheduling on the 20th of each month, no matter what day of the week the 20th is, you can only use the following notation: 13 13 15 20 * ?, where the last digit can only be used? , and cannot be used , if it is used to indicate that it will fire regardless of the day of the week, which is not the case.
  • L: Indicates the last, can only appear in and , if using 5L, means triggering on the last Thursday.
  • W: Indicates a valid working day (Monday to Friday), which can only appear in the domain. The system will trigger the event on the valid working day closest to the specified date. For example: When using 5W, if the 5th is Saturday, it will trigger on the nearest working day: Friday, which is the 4th. If the 5th is a Sunday, it will fire on the 6th; if the 5th is one of Monday to Friday, it will fire on the 5th. Another point, W's most recent searches don't span months.
  • #: Used to determine the day of the week in each month, can only appear on . For example, in 4#2, it means the second Wednesday of a month.

Reference documentation :

  1. Online Cron Expression Generator
  2. QuartZ Cron Expression Details

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324653387&siteId=291194637