Detailed cron expression! ! ! !

What is Cron

Cron expression is a string of 5 or 6 separated by a space, is divided into six or seven domains, each domain representing a meaning, Cron following two syntax:

(1) Seconds Minutes Hours DayofMonth Month DayofWeek Year

(2)Seconds Minutes Hours DayofMonth Month DayofWeek

First, the structure

corn left to right (separated by spaces): second minute hour day of the month date week month year

Second, the meaning of each field in the
field of special characters granted value
seconds (Seconds The) is an integer of 0 to 59, - * / four characters
min (Minutes) an integer of 0 to 59, - * / character four
hours (Hours) 0 an integer of 23 - * / four characters
integer date (dayofMonth) 1 ~ 31 (but you need to consider the number of days you month), -? * / LWC eight characters of
the month (month) integer of 1 to 12, or JAN -DEC, - * / four characters
integer week (DayofWeek) 1 ~ 7 or SUN-SAT (1 = SUN) , -? * / LC # eight characters
in (optional, leave blank) (Year) 1970 ~ 2099 - * / four characters

Precautions:

Each domain numbers, but can also appear as special characters, their meanings are:

(1) : represents any value matches the domain. If used in the Minutes field , it means that every minute a trigger event.

(2) it can only be used ?: DayofMonth and DayofWeek two domains. It also matches any value of the field, but actually not. Because DayofMonth and DayofWeek affect each other. For example, want to trigger scheduled on the 20th of each month, regardless of the 20 in the end of the week, you can only use the following wording:? 13,131,520 *, which can only be the last one? , * Can not be used, no matter if you use * Indicates day of the week will be triggered, in fact not the case.

(3) -: indicates a range. 5-20 Minutes domain using, for example, represents from 5 minutes assigned triggered once every 20 minutes

(4) /: indicating a start time of a start trigger, and a trigger every predetermined time. For example, using 5/20 in Minutes field, it means five minutes from the start trigger once every 20 minutes. Recently three runs is 5,25,45

(5) ,: listed represent the enumeration values. For example: the use of 5,20 in Minutes field, it means that the trigger once per minute at 5 and 20 minutes.

(6) L: represents the last, and only appeared in DayofWeek DayofMonth domain. If you use 5L in DayofWeek domain, meaning that triggered last Thursday.

(7) W: represents the effective working days (Monday to Friday), can only appear in DayofMonth domain, the system will trigger events in recent days from the effective date specified. For example: the use of 5W in DayofMonth, if the 5th is a Saturday, then in recent days: Friday that the 4th trigger. If the 5th is a Sunday, then on the 6th (Zhouyi) is triggered; if, in the Friday day, it triggers on Monday 5th in the 5th. Another point, W recently looking for does not cross the month.

(8) LW: These two characters can be used in conjunction, it represents the last working day in a month, and last Friday.

(9) #: means for determining a month the first few days of the week, only appear in DayofMonth domain. For example, in 4 # 2, it represents the second Wednesday of the month.

Third, the common expression examples

(1) 0021 *? * Indicates adjustment in 2:00 on the 1st of each month mission

(2) 0 15 10? * MON-FRI said on Monday through Friday at 10:15 am every day to perform the job

? (3) 0 15 10 6L 2002-2006 represents 2002-- last Friday at 10:15 am for the implementation of the 2006 monthly

(4) 00 10,14,16 * *? 10:00 every day, 14:00, 4:00

(5) * * 0 0/30 9-17? Inward nine to five hours every half hour

(6) 0 0 12? * WED represent every Wednesday 12:00

(7) 0012 * *? 12:00 every day trigger

(8) 01 510? * * Trigger every day at 10:15 am

(9) 01510 * *? Triggered daily at 10:15 am

(10) 01510 * *? * Trigger every day at 10:15 am

(11) 01510 * *? 2005 2005 at 10:15 am every day trigger

(12) 0 14 * * *? Triggered during every minute of every day at 2:00 pm to 2:59 pm

(13) 0/5 0 14 * *? During 2:00 pm to 2:55 pm each day of the trigger every 5 minutes

Every 5 minutes trigger (14) 0/5 0 * 14, 18 *? And 6:00 pm to 6:55 during the period of 2:00 to 2:55 every afternoon

(15) 00-514 * *? During 2:00 pm to 2:05 pm every day of every 1 minute when the

(16) 0 10,44 14? ​​3 WED Wednesday of March each year 2:10 pm and 2:44 trigger

(17) 0 15 10? * MON-FRI 10:15 am Monday through Friday, triggering

(18) 0151015 *? Trigger 15th of each month at 10:15 am

(19) 0 15 10 L *? 10:15 am on the last day of each month triggered

(20) 0 15 10? * 6L last Friday of each month at 10:15 am triggering

(21) 0 15 10? * 6L 2002-2005 2002 to 2005 years last Friday of each month at 10:15 am triggering

(22) 01 510? * 6 # 3 the third Friday of each month at 10:15 am triggering

Precautions

(1) Some sub-expressions can contain a range or list
such as: sub-expressions (days (weeks)) can be "MON-FRI", "MON, WED, FRI", "MON-WED, SAT", " " character represents all possible values, therefore, " " indicates the meaning of each month in the sub-expression (month), the "*" in the sub-expression (days (weeks)) represent each day of the week
(2) "/" character is used to increment a specified value
, for example: in the subexpression (minutes) in the "0/15" starts from 0 minutes, every 15 minutes
in the sub-expression (minutes) in the "3/20" indicates the the first three minutes, every 20 minutes (and it "3,23,43") meaning as "?" character is used only day (month) and day (week) two sub-expression that do not specify a value when one of the two sub-expressions which are assigned a value in the future, in order to avoid conflict, you need to set the value of the other sub-expression "?", "L" character is used for day (month) and day (week) only two subexpression, it is an abbreviation of the word "last", but its meaning in the two sub-expressions are not of. Day (month) sub-expression, "L" represents the last day of the month, in days (weeks) from the expression, "L" represents the last day of the week, which is the SAT. If there are specific content in the "L" before, it has other meanings of. For example: "6L" the reciprocal of the sixth day of the month, "FRIL" represents the best Friday of the month. Note: When using the "L" parameter, do not specify the list or range, as this can cause problems! ! !

Here is the address generated online cron: cron Online Generator

Guess you like

Origin blog.csdn.net/qq_43419029/article/details/92621788