Understanding Quartz Cron Expressions
A Quartz cron expression is a string consisting of 6 required fields (and 1 optional year field) separated by spaces. Unlike standard Unix cron which has 5 fields, Quartz adds a seconds field and supports additional special characters. This format is used by Java Quartz Scheduler, Spring Boot @Scheduled, and many enterprise job scheduling systems.
┌───────────── second (0-59)
│ ┌───────────── minute (0-59)
│ │ ┌───────────── hour (0-23)
│ │ │ ┌───────────── day of month (1-31)
│ │ │ │ ┌───────────── month (1-12 or JAN-DEC)
│ │ │ │ │ ┌───────────── day of week (1-7 or SUN-SAT, SUN=1)
│ │ │ │ │ │ ┌───────── year (1970-2099, optional)
│ │ │ │ │ │ │
* * * * * * *
Quartz vs Standard Cron: Key Differences
Field Count and Order
Standard Unix cron uses 5 fields (minute, hour, day, month, weekday). Quartz uses 6-7 fields starting with seconds. If you have a 5-field expression, use our standard Cron Expression tool instead.
Day-of-Week Numbering
In standard cron, days are numbered 0-6 (Sunday=0). In Quartz, days are numbered 1-7 (Sunday=1). This is a common source of bugs when converting between formats.
The ? (Question Mark) Character
Quartz requires ? in either the day-of-month or day-of-week field (but not both). The ? means "no specific value". It tells Quartz to ignore that particular day constraint. Standard cron doesn't have this character.
L, W, and # Characters
Quartz supports L (last), W (nearest weekday), and # (nth occurrence), none of which exist in standard cron. These enable powerful scheduling like "last Friday of the month" or "nearest weekday to the 15th".
Quartz Special Characters Explained
? (No Specific Value)
Used in day-of-month or day-of-week only. One field must use ? while the other specifies the constraint. Example: 0 0 9 ? * 2-6 means "9 AM on weekdays" (day-of-month doesn't matter).
L (Last)
In day-of-month: L means the last day of the month (28th, 29th, 30th, or 31st depending on the month). L-3 means 3 days before the last day.
In day-of-week: 6L means the last Friday of the month. 1L means the last Sunday of the month.
W (Nearest Weekday)
Used in day-of-month only. 15W means "the nearest weekday to the 15th". If the 15th is Saturday, it fires on Friday the 14th. If the 15th is Sunday, it fires on Monday the 16th. LW means "the last weekday of the month".
# (Nth Occurrence)
Used in day-of-week only. 6#3 means "the 3rd Friday of the month". 2#1 means "the 1st Monday of the month". Valid occurrence values are 1-5.
Where Quartz Cron Expressions Are Used
Java Quartz Scheduler
The original Quartz Scheduler library for Java uses this format. Configure triggers with CronScheduleBuilder.cronSchedule("0 0 12 * * ?") to schedule jobs.
Spring Boot @Scheduled
Spring's @Scheduled(cron = "0 0 9 * * ?") annotation uses Quartz-compatible 6-field cron expressions. Note that Spring 6+ uses a slightly different cron parser but is largely compatible with Quartz syntax.
Other Systems
Many enterprise systems use Quartz-format cron: Apache Camel, Camunda, Activiti, Jenkins (with Quartz plugin), and various ESBs and workflow engines.
Common Mistakes with Quartz Cron
- Forgetting the seconds field: If you write
0 12 * * ? (5 fields), that's standard cron format. Quartz needs 6 fields. Prepend 0 for seconds: 0 0 12 * * ?.
- Using both day fields without ?: Quartz requires
? in one of the day fields. 0 0 12 1 * 6 is invalid. Use 0 0 12 1 * ? or 0 0 12 ? * 6.
- Wrong day-of-week numbering: In Quartz, Sunday=1, Monday=2, ..., Saturday=7. This is different from Unix cron where Sunday=0.
- Mixing standard cron syntax: Don't use
0 for Sunday in the day-of-week field. In Quartz, use 1 for Sunday.
- Using L, W, # in standard cron: These characters only work in Quartz. Standard crontab will reject them.