Spring cron format
A Spring cron expression always has exactly six fields — there is no year field:
| Field | Allowed values | Special characters |
|---|---|---|
| Second | 0–59 | , - * / |
| Minute | 0–59 | , - * / |
| Hour | 0–23 | , - * / |
| Day of month | 1–31 | , - * ? / L W |
| Month | 1–12 or JAN–DEC | , - * / |
| Day of week | 0–7 or MON–SUN (0 and 7 = Sunday) | , - * ? / L # |
Special characters
| Symbol | Meaning |
|---|---|
? | Same as *. Spring accepts it in the day fields so that Quartz-style expressions still work. |
L | Last: L is the last day of the month and L-3 is three days before it; 5L or FRIL is the last Friday of the month. |
W | The weekday nearest to a date: 1W is the first weekday of the month, LW the last. |
# | The nth weekday: 5#2 or FRI#2 is the second Friday of the month. |
@ | Macros: @yearly, @monthly, @weekly, @daily (or @midnight) and @hourly. |
Spring cron examples
Click an expression to load it into the generator above.
| Expression | Schedule |
|---|---|
| Every 5 minutes. | |
| At 0 minutes past the hour. | |
| At 8:00 AM, Monday through Friday. | |
| At 0 minutes past the hour, between 9:00 AM and 5:59 PM, Monday through Friday. | |
| At 12:00 AM, on day 25 of the month, only in December. | |
| At 12:00 AM, on the last day of the month. | |
| At 12:00 AM, on the last weekday (Monday to Friday) of the month. | |
| At 12:00 AM, on the last Thursday of the month. | |
| At 12:00 AM, on the second Friday of the month. | |
| At 12:00 AM. |
How Spring cron differs from Unix cron
- Six fields with seconds first. A five-field Unix expression fails with “Cron expression must consist of 6 fields” — put
0in front of it:*/5 * * * *becomes0 */5 * * * *. - Sunday is
0or7, as in Unix cron — not1as in Quartz. - If you set both a day of month and a day of week, Spring runs only on days that match both. Unix cron runs when either one matches.
- There is no year field, and
?simply means*.
Use it with @Scheduled
Enable scheduling once with @EnableScheduling, then annotate a method. The zone attribute sets the time zone; without it the server’s default is used:
@Configuration
@EnableScheduling
class SchedulingConfig {}
@Component
class ReportJob {
@Scheduled(cron = "0 0 8 * * MON-FRI", zone = "Asia/Riyadh")
void sendDailyReport() {
// 08:00 Riyadh time, Monday to Friday
}
}
To change the schedule without a release, read it from configuration with @Scheduled(cron = "${report.cron}"), and set report.cron=- to switch the job off.
Frequently asked questions
Why does Spring say “Cron expression must consist of 6 fields”?
Spring expects a seconds field before the minutes. Add 0 at the start of a five-field expression: 0 9 * * 1-5 becomes 0 0 9 * * 1-5 (09:00 on weekdays).
How do I set the time zone of a @Scheduled job?
Use the zone attribute: @Scheduled(cron = "0 0 2 * * *", zone = "Europe/London"). Without it, Spring uses the default time zone of the server, which is often UTC.
Does Spring support L, W and # like Quartz?
Yes, since Spring Framework 5.3 (Spring Boot 2.4): L, L-3, LW, 15W, 5L and 5#2 all work. Spring numbers Sunday as 0 or 7, so the last Friday is 5L in Spring but 6L in Quartz.
Cron generators for other platforms
*/15 8-18 * * 1-5
Quartz Cron Expression Generator
0 0 8 ? * MON-FRI
AWS Cron Expression Generator
0 8 ? * MON-FRI *
Jenkins Cron Expression Generator
H 2 * * 1-5
Salesforce Cron Expression Generator
0 0 8 ? * MON-FRI
Hangfire Cron Expression Generator
0 8 * * 1-5
Airflow Cron Expression Generator
0 6 * * 1-5
node-cron Expression Generator
0 30 8 * * 1-5