Use cron expressions

更新时间:
复制 MD 格式

This topic describes how to set cron expressions.

Cron is suitable for recurring tasks, routine maintenance, and one-time tasks that must run at a specific time. A cron expression is a string that represents a time schedule. The string is divided into six fields separated by spaces, in the format X X X X X X. In this format, X is a placeholder for a field. If a field contains multiple values, use a comma (,) to separate them. Each field can contain a specific value or a special character that has a logical meaning.

Field values

The following table describes the valid values and supported special characters for each of the six fields in a cron expression.

Field

Required

Value range

Special characters

Second

Yes

[0, 59]

Not supported

Minute

Yes

[0, 59]

Limited support for commas (,) and forward slashes (/). If you use a comma, the interval between the numbers must be 30 minutes or more. If you use a forward slash, the number after the slash must be 30 or more.

Hour

Yes

[0, 23]

* , - /

Date

Yes

[1, 31]

* , - / ? L

Month

Yes

[1, 12] or [JAN, DEC]

* , - /

Week

Yes

[1, 7] or [SUN, SAT]. If you use the 1 to 7 format, 1 represents Sunday and 2 represents Monday.

* , ?

Special characters

Each field in a cron expression supports special characters. Each special character has a specific meaning.

Special character

Meaning

Example

*

All possible values.

In the Month field, * means every month. In the Day-of-week field, * means every day of the week.

,

Enumeration values.

In the Minute field, 5,40 means the task is triggered at 5 and 40 minutes past the hour.

-

Scope

In the Day-of-month field, 5-20 means the task is triggered every day from the 5th to the 20th of the month.

/

Specifies an increment for a value.

In the Day-of-month field, 1/5 means every 5 days, starting on the first day of the month. In the Hour field, 3/8 means every 8 hours, starting at the third hour of the day.

?

Indicates no specific value. This character is supported only in the Day-of-month and Day-of-week fields.

When a value is specified for either the Day-of-month or Day-of-week field, set the other field to ? to avoid conflicts.

L

Stands for 'last' and means the last day. This character is supported only in the Day-of-month field. Note When you specify the L character, do not specify a list or a range. Otherwise, logical conflicts may occur.

In the Day-of-month field, L means the last day of the month.

Examples

The following table shows examples of cron expressions.

Example

Description

0 15 10 ? * *

Runs the task at 10:15 every day.

0 15 10 * * ?

Runs the task at 10:15 every day.

0 0 12 * * ?

Runs the task at 12:00 (noon) every day.

0 0 10,14,16 * * ?

Runs the task at 10:00, 14:00, and 16:00 every day.

0 0/40 9-17 * * ?

Runs the task every 40 minutes from 09:00 to 17:00 every day.

0 0 12 ? * WED

Runs the task at 12:00 (noon) every Wednesday.

0 15 10 15 * ?

Runs the task at 10:15 on the 15th of every month.

0 15 10 L * ?

Runs the task at 10:15 on the last day of every month.

0 0,30 14 ? 3 WED

Runs the task at 14:00 and 14:30 every Wednesday in March.