Field layout: seconds first
Quartz prepends a seconds field to everything you know from Unix cron, then appends an optional year field. That single extra field at the front is why a five-field Unix expression fails validation in Quartz, and why copying a Quartz expression into a crontab can appear to work while firing at the wrong time.
| Position | Field | Allowed values | Special characters |
|---|---|---|---|
| 1 | Second | 0–59 | , - * / |
| 2 | Minute | 0–59 | , - * / |
| 3 | Hour | 0–23 | , - * / |
| 4 | Day of month | 1–31 | , - * / ? L W |
| 5 | Month | 1–12 or JAN–DEC | , - * / |
| 6 | Day of week | 1–7 (SUN=1) or SUN–SAT | , - * / ? L # |
| 7 (optional) | Year | 1970–2099 | , - * / |
Quartz numbers days of the week 1–7 with Sunday = 1. Unix cron uses 0–6 with Sunday = 0. Monday is 2 in Quartz and 1 in Unix.
The special characters Quartz adds
Quartz supports everything Unix cron does, plus four operators that exist because the day-of-month and day-of-week fields cannot both be specified. In Quartz you must put ? in one of those two fields; it means “no specific value”, not “every value”.
?— no value in day-of-month or day-of-week. Exactly one of the two fields must be?.L— last. In day-of-month it means the last day of the month; in day-of-week it means the last occurrence of that weekday (6L= last Friday).W— nearest weekday to the given day (15W= the weekday closest to the 15th, never crossing the month boundary).#— nth weekday of the month (MON#2or2#2= the second Monday).
Quartz expressions worth copying
0 0 9 * * ? # every day at 09:00:00
0 0 9 ? * MON-FRI # weekdays at 09:00:00
0 0 0 1 * ? # first day of every month at midnight
0 0 0 L * ? # last day of every month
0 0 0 15W * ? # nearest weekday to the 15th
0 0 0 ? * 6L # last Friday of every month
0 0 0 ? * MON#2 # second Monday of every month
0 0 0 1 1 ? 2030 # January 1, 2030 at midnight
Migrating between Quartz and Unix cron
The migration is not a text substitution. Remove the seconds field, renumber the weekday, replace ? with * where appropriate, and replace L, W and # with a date-guarded script. After conversion, verify the expression with the next-run calculator rather than trusting the diff.
0 0 9 ? * MON-FRI(Quartz) becomes0 9 * * 1-5(Unix).0 0 0 L * ?has no Unix equivalent; run daily and check whether tomorrow is the 1st.0 0 0 ? * MON#2has no Unix equivalent; run every Monday and check the date is between 8 and 14.0 0 0 1 1 ? 2030must be handled by an external date check in Unix cron.
Spring's @Scheduled(cron = "...") uses six fields by default (seconds first), while @Scheduled(cron = "...", zone = "...") still interprets Spring's own cron syntax, which is not identical to Unix crontab syntax.