Cron expression example:
*/5 * * * * ?
: run every 5 seconds0 */1 * * * ?
: run every 1 minute0 0 23 * * ?
: Execute once a day at 23:000 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 month0 0 23 L * ?
: Executed at 23:00 on the last day of every month0 0 1 ? * L
: Executed once a week at 1:00 a.m. on Sundays0 26,29,33 * * * ?
: Execute once at 26 minutes, 29 minutes, and 33 minutes0 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 :