CRON
Expression interpreter
of month
of week
| Name | Required | Allowed values | Allowed special characters |
|---|---|---|---|
seconds | Yes | 0-59 | , - * / |
minutes | Yes | 0-59 | , - * / |
hours | Yes | 0-23 | , - * / |
days of month | Yes | 1-31 | , - * ? / L W |
months | Yes | 1-12 or JAN-DEC | , - * / |
days of week | Yes | 1-7 or SUN-SAT 1 = Sunday, 7 = Saturday | , - * ? / L # |
years | No | empty or 1970-2099 | , - * / |
| Sign | Explanation |
|---|---|
, | Separates consecutive values. |
- | Specifies a range from-to. |
* | All values for the field, e.g., in the hour field means 'every hour'. |
? | Useful when it is necessary to specify a value in one of two fields where the character is allowed but not in the other. For example, if I want the trigger to run on the 5th day of the month but don't care about which day of the week it is, I will put '5' in the day of the month field and '?' in the day of the week field. In this dialect exactly one of the day-of-month and day-of-week fields must be '?' - using a value in both, or '*' in both, is rejected. |
/ | Used to specify steps. The first value indicates when the step starts, and the second value indicates how often the step will be performed, e.g., '0/15' in the minute field means minutes 0, 15, 30, 45, while '5/15' means execution at minute 5, 20, 35, and 50. |
# | The hash '#' is used to specify the 'nth' day of the month, e.g., value '4#3' in the day of the week field means the third Wednesday of the month (day 4 = Wednesday and #3 = third Wednesday of the month). |
L | The letter 'L' means 'last' in the day of the week or day of the month fields. For example, '0 0 9 ? * 3L' means the last Tuesday of every month at 9 AM. In the day of the month field, you can also specify 'LW', meaning the last weekday of the month. Used alone in the day-of-week field ('L' by itself, with no day before it), it means Saturday (day 7), not 'the last day of the week'. |
W | Specifies the nearest weekday (Monday to Friday) to the given day of the month. For example, '1W' means 'nearest weekday to the 1st day of the month'. If the 1st falls on a Sunday, the cron will be triggered on Monday, the 2nd of the month. |
| Expression | Description |
|---|---|
0 0 12 * * ? | Execute every day at 12:00. |
0 0/20 * * * ? | Execute every 20 minutes, at minutes 0, 20, 40. |
0 15 10 * * ? 2023 | Execute at 10:15 every day in the year 2023. |
* 30 3 ? * 1,7 | Execute every second at 3:30 on Saturday and Sunday. |
| This tool (Quartz) | Spring CronExpression | Classic Unix cron | |
|---|---|---|---|
Number of fields | 6 or 7 | 6 | 5, no seconds |
'?' in day-of-month / day-of-week | required in exactly one field | optional, acts like '*' | not supported |
Day-of-month and day-of-week together | rejected | allowed - both must match (AND) | allowed - either matches (OR) |
Day-of-week numbering | 1 = Sunday … 7 = Saturday | 0 or 7 = Sunday, 1 = Monday | 0 or 7 = Sunday, 1 = Monday |