Cron expression verification

Cron expression:
Cron online generation tool

Function introduction


Detailed cron expression

Cron expression is a string separated by 5 or 6spaces and divided into 6 or 7fields, each representing a meaning. Cron has two syntax formats:

(1) Seconds Minutes Hours DayofMonth Month DayofWeek Year

(2) Seconds Minutes Hours DayofMonth Month DayofWeek

1, structure

Cron left-to-right (separated by spaces): second, minute, hour, month, date, month, week, year

2. Meaning of each field

field Allowable Value Allowed special characters
Seconds Integer 0~59 , -* / four characters
Score (Minutes) Integer 0~59 , -* / four characters
Hours (Hours) Integer 0~23 , -* / four characters
Date (DayofMonth) Integer from 1 to 31 (but you need to consider the number of days in your month) -*?/ L W C eight characters
Month (Month) 1~12 integer or JAN-DEC , -* / four characters
Week (DayofWeek) Integer from 1 to 7 or SUN-SAT (1=SUN) , - *?/ L C # eight characters
Year (optional, leave blank) (Year) 1970~2099 , -* / four characters

Notes:

Numbers are used in each field, but the following special characters can also appear, meaning:

(1)*: indicates any value that matches the field.If*is used in the Minutes field, it means that events are triggered every minute.

(2)?: Can only be used in DayofMonth and DayofWeek domains.It also matches any value of the domain, but does not actually Because DayofMonth and DayofWeek interact.For example, if you want to trigger a schedule on the 20th of each month, no matter what day of the week the 20th is, you can only use the following: 13 13 15 20 *?, of which the last one can only be used?Instead of using *, if you use * to indicate that it will trigger no matter what day of the week, this is not really the case.

(3)-: indicates range.For example, using 5-20 in the Minutes field means triggering  once per minute from 5 minutes to 20 minutes;

(4)/: indicates that the start time starts to trigger, and then triggers every fixed time.For example, using 5/20 in the Minutes field means firing once in five minutes, and 25,45, respectively.

(5),: means listing enumerated values.For example, using 5,20 in the Minutes field means triggering every minute at 5 and 20 minutes.

(6) L: means that at the end, it can only appear in the DayofWeek and DayofMonth domains.If you use 5L in the DayofWeek field, it means it will fire on the last Thursday.

(7) W: Represents a valid working day (Monday to Friday), can only appear in the DayofMonth field, and the system will trigger events on the closest valid working day to the specified date.For example: DayofMonth uses 5W, which will trigger on the nearest working day, Friday, or 4, if the 5th day is Saturday.If the 5th day is Sunday, it triggers on the 6th (Monday); if the 5th day is Monday to Friday, it triggers on the 5th.On the other hand, W's most recent search does not span months.

(8) LW: These two characters can be used together to indicate the last working day of a month, that is, the last Friday.

(9)#: Used to determine the day of the week of a month and can only appear in the DayofWeek field.For example, at 4#2, the second Wednesday of a month.

3. Examples of common expressions

(0) 0/20 * * * * ? denotes every 20 seconds Adjust Tasks

(1) 0 0 2 1 * ? indicates that the task is adjusted at 2 a.m. each month

(2) 0 15 10 ? * MON-FRI Indicates Monday to Friday at 10:15 a.m. daily

(3) 0 15 10 ? 6L 2002-2006 Represents the last Friday of each month, 2002-2006, at 10:15 a.m.

(4) 0 0 10,14,16 * * ? 10 a.m., 2 p.m., 4 p.m.

(5) 0 0/30 9-17 * * ? Every half hour of working hours towards 9:5

(6) 0 0 12 ? * WED means 12 o'clock  every Wednesday;

(7) 0 0 12 * * ? trigger every day at 12:00 p.m.

(8) 0 15 10 ? * * triggered every day at 10:15 a.m.

(9) 0 15 10 * * ? Trigger  every day at 10:15 a.m.

(10) 0 15 10 * * ? * trigger  every day at 10:15 a.m;

(11) 0 15 10 * * ? 2005 trigger  every morning at 10:15 in 2005;

(12) 0 * 14 * * ? Trigger  every minute between 2 pm and 2:59 pm each day;

(13) 0 0/5 14 * * ? triggers  every 5 minutes between 2 p.m. and 2:55 p.m. each day;

(14) 0 0/5 14,18 * * ? Trigger  every 5 minutes between 2 p.m. and 2:55 p.m. and between 6 p.m. and 6:55 p.m.

(15) 0 0-5 14 * * ? triggers every minute between 2 p.m. and 2:05 p.m. each day;

(16) 0 10,44 14 ? 3 WED triggers  every Wednesday, March at 2:10 and 2:44 p.m.

(17) 0 15 10 ? * MON-FRI triggered at 10:15 a.m. Monday to Friday;

(18) 0 15 10 15 * ? trigger  every 15 days at 10:15 a.m.

(19) 0 15 10 L * ? trigger  at 10:15 on the last day of each month;

(20) 0 15 10 ? * 6L triggers  at 10:15 on the last Friday of each month;

(21) 0 15 10 ? * 6L 2002-2005 Trigger  at 10:15 a.m. on the last Friday of each month from 2002 to 2005;

(22) 0 15 10 ? * 6#3 Triggered at 10:15 a.m. on the third Friday of each month

Note:

(1) Some subexpressions can contain ranges or lists

For example, the subexpression (day (week)) can be "MON-FRI", "MON, WED, FRI", "MON-WED, SAT"

The '*' character represents all possible values

Therefore,'*' denotes the month in the subexpression (month), and '*' denotes the day of the week in the subexpression (day (week)).

The
'/' character is used to specify the increment of a value
For example,'0/15' in a subexpression (minutes) means starting at minute 0 and every 15 minutes
in a subexpression (minutes) means starting at minute 3 and every 20 minutes (it has the same meaning as'3, 23, 43')


'?' Character is only used in day(month) and day(week) subexpressions to indicate that no value is specified;
When one of the two subexpressions has a value specified, you need to set the value of the other subexpression to '?' to avoid conflicts.

The 'L' character is used only in day(month) and day(week) subexpressions, which are abbreviations for the word "last"
but have different meanings in the two subexpressions.
In the day (month) subexpression, 'L' indicates the last day of a month
In the day (week) from the expression, 'L' indicates the last day of a week, that is, SAT

If there is something specific before 'L', it has other meanings

For example,'6L'means the last sixth day of the month,"FRIL" means the last Friday of the month
Note: Do not specify a list or range when using the 'L' parameter, as this can cause problems

Recently used:

BM Nav QQ