When setting scheduling plans for scheduled tasks, if the execution frequency you want to set is too complicated to be achieved by Execute Repeatedly or Set Detailed Frequency, you can use a Cron expression.
This document introduces how to write a Cron expression.
A Cron expression is a string comprising six or seven fields separated by five or six white spaces, with each field representing a time range. A Cron expression can be written in the following two syntax formats:
Seconds Minutes Hours DayofMonth Month DayofWeek Year
Seconds Minutes Hours DayofMonth Month DayofWeek
Characters allowed in each field are shown in the following table.
Seconds
0 to 59 (integers)
Four characters: comma (,), hyphen (-), asterisk (*) and slash (/)
Minutes
Hours
0 to 23 (integers)
DayofMonth
0 to 31 (integers, the number of which depends on the specific month)
Eight characters: comma (,), hyphen (-), asterisk (*), question mark (?), slash (/), L, W, and C
Month
1 to 12 (integers) or JAN to DEC ( month abbreviation)
DayofWeek
1 to 7 (integers) or SUN to SAT (1=SUN, 2=MON, ...)
Eight characters: comma (,), hyphen (-), asterisk (*), question mark (?), slash (/), L, C, and hash (#)
Year
1970 to 2099
In addition to numbers, each field can also contain special characters, the meaning of which is shown in the following table.
*
Indicates any value of the field. For example, if you use the asterisk (*) in Minutes, the event is triggered every minute.
?
Allowed only in DayofMonth and DayofWeek. This character also indicates any value of the two fields, but, in fact, it does not, because DayofMonth and DayofWeek affect each other. For example, if you want to trigger scheduling on the 20th of every month regardless of what day of the week the 20th is, you can only write the expression as 13 13 15 20 * ?, in which the last character can only be the question mark (?) rather than the asterisk (*). Because if you use the asterisk (*) in DayofWeek that indicates any day of the week, it will contradict the 20th of every month.
-
Indicates the range. For example, If you use 5 - 20 in Minutes, the event is triggered every minute from the 5th to the 20th minute.
/
Indicates that the event is triggered at the start time and then triggered at each fixed interval. For example, If you use 5/20 in Minutes, the event is triggered at the 5th minute and continues to be triggered every 20 minutes. (For example, the event is triggered at the 25th and 45th minutes.)
,
Indicates listing enumeration values. For example, If you use 5,20 in Minutes, the event is triggered at the 5th and 20th minutes respectively.
L
Represents "Last" and only allowed in DayofMonth and DayofWeek. However, this character has different meanings in the two fields. L represents the last day of a month in DayofMonth (for example, the 31st of January, or the 28th of February in a non-leap year). If L is used in DayofWeek, it means Saturday, equivalent to 7. However, if there is a numeric value before L, the character L takes on a different meaning. For example, 6L in DayofMonth means the sixth-to-last day of the month, and FRIL in DayofWeek means the last Friday of the month.
W
Modifies the preceding date and only allowed in DayofMonth. This character means the nearest weekday (Monday to Friday) to that date. For example, 15W represents the nearest weekday (Monday to Friday) to the 15th day of the month. If the 15th day of that month falls on a Saturday, then the character represents the 14th day (Friday). If the 15th day falls on a Sunday, then it represents the 16th day (Monday). And if the 15th day falls on a Tuesday, then it represents the 15th day (Tuesday). However, the associated matching date cannot span across months. For example, if you specify 1W and the 1st day falls on a Saturday, then the field represents the 3rd day (Monday) of the current month instead of the last day of the previous month. W can only be used to specify a single date, not a date range.
LW
Allowed in DayofMonth in combination. This combination means the last workday (Monday to Friday) of the current month.
C
Represents "Calendar" and only allowed in DayofMonth and DayofWeek. This character is used to specify an associated date. If the date is not associated, then the character represents all dates in the calendar. For example, 5C in DayofMonth is equivalent to the first day after the 5th day of the month. 1C in DayofWeek is equivalent to the first day after Sunday.
#
Indicates a certain workday (Monday to Friday) of the month and only allowed in DayofWeek. For example, 6#3 represents the third Friday of the month (6 represents Friday and #3 represents the third). Similarly, 4#5 represents the fifth Wednesday of the month. If there is no fifth Wednesday in the month, then the field is not triggered.
For example, you want to implement a scheduled task that updates at 8:00 AM every Monday to Friday.
1. Set a timed scheduling plan for the task, as shown in the following figure.
2. Set Execution Frequency to Set Expression on the Single Task Scheduling setting page, and enter the corresponding Cron expression.
This Cron expression means that the update is executed at 8:00 AM every Monday to Friday.
3. Click OK and the setting is completed.
The Cron expression can be further expanded here.
0 0 8 ? * 2-6
Means that the task is executed at 8:00 AM every Monday to Friday.
0 0/5 8-9 ? * 2-6
Means that the task is executed every five minutes between 8:00 AM and 9:00 AM, every Monday to Friday.
0 0 8,17 ? * 2-6
Means that the task is executed at 8:00 AM and 5:00 PM every Monday to Friday.
0 0 8,13 * * ?
Means that the task is executed at 8:00 AM and 1:00 PM every day.
0 0 8-18 ? * MON-FRI
Means that the task is executed every full hour between 8:00 AM to 6:00 PM(during regular working hours) every Monday to Friday.
0 0 12 ? * 2#1
Means that the task is executed at 12:00 on the first Monday of every month.
0 * 14 * * ?
Means that the task is executed at 14:00 and continues to be executed every minute from 2:00 PM to 2:59 PM every day.
0 0/5 14 * * ?
Means that the task is executed at 2:00 PM and continues to be executed every five minutes from 2:00 PM to 2:55 PM every day.
0 55/10 14,18 * * ?
Means that the task is executed at 2:55 PM and 6:55 PM every day.
0 10,44 14 ? WED
Means that the task is executed at 2:10 PM and 2:44 PM every Wednesday in March.
0 15 10 ? * MON-FRI
Means that the task is executed at 10:15 AM every Monday, Tuesday, Wednesday, Thursday, and Friday.
0 15 10 15 * ?
Means that the task is executed at 10:15 AM on the 15th day of every month.
0 15 10 L * ?
Means that the task is executed at 10:15 AM on the last day of every month.
0 15 10 ? * 6L
Means that the task is executed at 10:15 AM on the last Friday of every month.
0 15 10 ? * 6L 2002-2005
Means that the task is executed at 10:15 AM on the last Friday of every month from 2002 to 2005.
0 15 10 ? * 6#3
Means that the task is executed at 10:15 AM on the third Friday of every month.
0 0 0 L-2 * ? *
Means that the task is executed on the second-to-last day of every month.
Simple Scenario
*/5 * * * * ?
Means that the task is executed every five minutes.
0 */1 * * * ?
Means that the task is executed every minute.
0 0 */1 * * ?
Means that the task is executed every hour.
0 0 12 * * ?
Means that the task is executed at 12:00 every day.
0 0 0,13,18,21 * * ?
Means that the task is executed at 00:00, 1:00 PM, and 9:00 PM every day.
0 0 0-8 * * ?
Means that the task is executed every full hour from 00:00 to 8:00 AM every day.
0 15 10 ? * *
Means that the task is executed at 10:15 AM every morning.
0 15 10 * * ?
0 15 10 * * ? *
0 15 10 * * ? 2024
Means that the task is executed at 10:15 AM every morning in 2024.
滑鼠選中內容,快速回饋問題
滑鼠選中存在疑惑的內容,即可快速回饋問題,我們將會跟進處理。
不再提示
10s後關閉
Submitted successfully
Network busy