Cron expressions

更新时间:
复制 MD 格式

Cron expressions define schedules for recurring tasks, routine maintenance, and one-time jobs.

A cron expression is a time-based string of six space-separated fields in the format X X X X X X, where each X represents a field value. Separate multiple values in a single field with a comma (,). Each field accepts a specific value or a special character.

Fields and values

The following table describes each field, its allowed values, and supported special characters.

Field

Required

Value range

Special character

Second

Yes

[0, 59]

Not supported

Minute

Yes

[0, 59]

Comma-separated values must be at least 30 minutes apart. Forward-slash increments must be 30 or greater.

Hour

Yes

[0, 23]

* , - /

day-of-month

Yes

[1, 31]

* , - / ? L

Month

Yes

[1, 12] or [JAN, DEC]

* , - /

day-of-week

Yes

[1, 7] or [SUN, SAT]. For the [1, 7] format, 1 represents Sunday, and 2 represents Monday.

* , ?

Special characters

The following special characters are supported in cron expression fields.

Special character

Description

Example

*

Matches all values in the field.

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

,

Lists multiple discrete values.

In the Minute field, 5,40 runs the task at 5 and 40 minutes past the hour.

-

Defines a contiguous range of values.

In the day-of-month field, 5-20 runs the task daily from the 5th to the 20th of each month.

/

Defines a step interval.

In the day-of-month field, 1/5 specifies the first day of the month and every 5 days thereafter. In the Hour field, 3/8 specifies the 3rd hour and every 8 hours thereafter.

?

No specific value. Valid only in the day-of-month and day-of-week fields.

The day-of-month and day-of-week fields are mutually exclusive. If you specify a value in one of these fields, you must use a ? in the other.

L

Stands for “last.” Only supported in the day-of-month field, meaning the last day of the month. Note: Do not combine L with a list or range, as this can cause logical conflicts.

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

Examples

The following table shows common cron expression patterns.

Example

Description

0 15 10 ? * *

Runs a task at 10:15 AM every day.

0 15 10 * * ?

Runs a task at 10:15 AM every day.

0 0 12 * * ?

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

0 0 10,14,16 * * ?

Runs a task at 10:00 AM, 2:00 PM, and 4:00 PM every day.

0 0/40 9-17 * * ?

Runs a task at 0 and 40 minutes past the hour, every day, from 9:00 AM to 5:59 PM.

0 0 12 ? * WED

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

0 15 10 15 * ?

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

0 15 10 L * ?

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

0 0,30 14 ? 3 WED

Runs a task at 2:00 PM and 2:30 PM on every Wednesday in March.

0 0 1 ? * 4#1

Runs a task at 1:00 AM on the first Wednesday of every month.