Cron Expression Generator for Spring Boot @Scheduled
Table of Contents
Spring Boot's @Scheduled annotation takes cron expressions — but Spring uses a 6-field format that adds a seconds field at the start. Most online cron tools generate standard 5-field Unix cron, which won't work directly. This guide clears up the difference and shows you how to build the right expression for your Spring application.
You can use our free cron expression generator to build the 5-field base, then adjust for Spring's 6-field format — or use the platform-specific patterns below.
Spring Boot vs Standard Cron: The Key Difference
Standard Unix cron uses 5 fields: minute, hour, day-of-month, month, day-of-week. Spring Boot's @Scheduled(cron = "...") uses 6 fields, with seconds as the first field:
| Field | Standard Cron | Spring Boot Cron |
|---|---|---|
| 1 | Minute (0-59) | Seconds (0-59) |
| 2 | Hour (0-23) | Minute (0-59) |
| 3 | Day of month (1-31) | Hour (0-23) |
| 4 | Month (1-12) | Day of month (1-31) |
| 5 | Day of week (0-6) | Month (1-12) |
| 6 | (not used) | Day of week (0-7) |
So if you want to run a job every day at 9:00 AM in standard cron, it's 0 9 * * *. In Spring Boot it's 0 0 9 * * * — that leading zero is the seconds field.
Common Spring Boot Cron Patterns for @Scheduled
Here are the most commonly needed Spring Boot cron patterns, ready to paste into your @Scheduled annotation:
| Schedule | Spring Boot Expression | Standard Cron Equivalent |
|---|---|---|
| Every minute | 0 * * * * * | * * * * * |
| Every 5 minutes | 0 */5 * * * * | */5 * * * * |
| Every 15 minutes | 0 */15 * * * * | */15 * * * * |
| Every hour | 0 0 * * * * | 0 * * * * |
| Daily at midnight | 0 0 0 * * * | 0 0 * * * |
| Daily at 9 AM | 0 0 9 * * * | 0 9 * * * |
| Weekdays at 9 AM | 0 0 9 * * MON-FRI | 0 9 * * 1-5 |
| Every 30 seconds | */30 * * * * * | Not supported |
| First day of month | 0 0 0 1 * * | 0 0 1 * * |
| Weekly on Sunday | 0 0 0 * * SUN | 0 0 * * 0 |
Spring Boot allows day-of-week names (MON, TUE, WED, THU, FRI, SAT, SUN) and month names (JAN through DEC), which makes expressions more readable than number-only formats.
Using @Scheduled in Your Java Spring Boot Code
Here is the basic pattern for scheduling a method in Spring Boot:
@Component
public class ReportScheduler {
@Scheduled(cron = "0 0 9 * * MON-FRI")
public void generateDailyReport() {
// Runs weekdays at 9 AM
}
@Scheduled(cron = "0 */15 * * * *")
public void syncData() {
// Runs every 15 minutes
}
@Scheduled(cron = "0 0 0 1 * *")
public void monthlyCleanup() {
// Runs on the 1st of every month at midnight
}
}
Also remember to add @EnableScheduling to your main application class or a configuration class — otherwise, Spring won't scan for @Scheduled annotations at all.
You can also externalize the cron expression to your application.properties file so you don't need to recompile when changing schedules:
# application.properties app.report.cron=0 0 9 * * MON-FRI
@Scheduled(cron = "${app.report.cron}")
public void generateDailyReport() { ... }
Sell Custom Apparel — We Handle Printing & Free Shipping
Special Spring Boot Cron Values
Spring Boot supports a few shorthand values beyond the standard numeric format:
- ? (question mark) — Used in day-of-month OR day-of-week fields (not both) to mean "no specific value." If you set day-of-week, use ? for day-of-month. Example:
0 0 9 ? * MON-FRI - L — Last day.
Lin day-of-month means the last day of the month.5Lin day-of-week means the last Friday of the month. - W — Nearest weekday.
15Win day-of-month means the weekday nearest to the 15th. - # — Nth occurrence.
MON#2means the 2nd Monday of the month.
These are Quartz-style extensions that standard Unix crontab does not support. Our online generator produces standard 5-field expressions that you convert by prepending a seconds field — typically 0 unless you need sub-minute scheduling.
Timezone Configuration for @Scheduled
By default, Spring uses the JVM's default timezone. If your server runs in UTC but you need jobs to run in EST, configure the timezone explicitly:
@Scheduled(cron = "0 0 9 * * MON-FRI", zone = "America/New_York")
public void generateESTReport() { ... }
Valid timezone IDs are the standard Java timezone identifiers: America/New_York, America/Los_Angeles, Europe/London, Asia/Tokyo, etc. Avoid using short timezone abbreviations like EST or PST — they're ambiguous and sometimes handled inconsistently across JVM versions.
For Docker deployments, you can also set the JVM timezone via the TZ environment variable, but explicit zone attributes in your @Scheduled annotations are more predictable and portable.
Testing Cron Expressions Before Deploying to Spring Boot
Before hardcoding a cron expression into production code, verify it using our free cron expression generator. Enter your desired schedule and it shows you the next 5 execution times so you can confirm it matches your intent.
For the 5-to-6-field conversion, build the expression using the 5-field generator, then prepend a 0 for the seconds field. So the tool output 0 9 * * 1-5 becomes Spring Boot expression 0 0 9 * * MON-FRI.
One common mistake: forgetting that 0/5 * * * * * and */5 * * * * * are both valid in Spring but mean slightly different things. The */5 starts at 0 and fires at 0, 5, 10, 15... The 0/5 also starts at 0 but is more explicit. Both work the same in practice for most cases.
Try It Free — No Signup Required
Runs 100% in your browser. No account, no install, no limits.
Open Free Cron GeneratorFrequently Asked Questions
Does Spring Boot use 5-field or 6-field cron expressions?
Spring Boot uses 6-field cron expressions. The extra field at the start is for seconds (0-59). Standard Unix cron uses 5 fields (minute, hour, day, month, weekday). To convert, prepend "0" to a standard expression: "0 9 * * 1-5" becomes "0 0 9 * * MON-FRI".
How do I schedule a Spring Boot job to run every 30 seconds?
Use the expression "*/30 * * * * *" in your @Scheduled annotation. This is only possible with Spring Boot's 6-field format — standard 5-field cron cannot schedule sub-minute intervals.
What does the question mark (?) mean in Spring cron expressions?
The question mark means "no specific value" and is used in the day-of-month or day-of-week field when you want to specify the other but not both. For example, "0 0 9 ? * MON-FRI" means weekdays at 9 AM, with ? indicating you're not specifying a day of month.
How do I set the timezone for a Spring Boot @Scheduled job?
Use the zone attribute: @Scheduled(cron = "0 0 9 * * *", zone = "America/New_York"). Use Java timezone IDs like "America/New_York", "Europe/London", or "Asia/Tokyo" rather than abbreviations like EST or PST.

