Quick revision
The short answer
In Spring's six-field cron format (second, minute, hour, day of month, month, day of week), every weekday at 06:30 is 0 30 6 * * MON-FRI, every 15 minutes during business hours is 0 */15 9-17 * * *, which runs from 09:00 up to 17:45, and the last day of every month at 23:00 is 0 0 23 L * *, using the L syntax Spring supports since 5.3. Unix cron has only five fields and no seconds, and Quartz cron needs a ? in one of the two day fields and allows an optional year.
What to remember
In this answer, we wrote the three schedules in Spring's six-field cron format: 0 30 6 * * MON-FRI for weekdays at 06:30, 0 */15 9-17 * * * for every quarter hour from 09:00 to 17:45, with two expressions if the last run must be 17:00, and 0 0 23 L * * for 23:00 on the last day of each month, using L from Spring 5.3. We checked each with CronExpression.next(), and saw that Unix cron has five fields without seconds, while Quartz cron needs a ? in a day field, numbers weekdays from Sunday as 1 and allows a year.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
In Spring's six-field cron format (second, minute, hour, day of month, month, day of week), every weekday at 06:30 is 0 30 6 * * MON-FRI, every 15 minutes during business hours is 0 */15 9-17 * * *, which runs from 09:00 up to 17:45, and the last day of every month at 23:00 is 0 0 23 L * *, using the L syntax Spring supports since 5.3. Unix cron has only five fields and no seconds, and Quartz cron needs a ? in one of the two day fields and allows an optional year.
Why this question is asked
Cron expressions are short, dense and unforgiving: a field in the wrong place still parses and silently means something else, such as once a year instead of once a day. Most teams also mix three dialects, Unix crontab, Spring and Quartz, which look alike but differ in field count and special characters. Interviewers ask for concrete expressions to see whether we can write and read them precisely and know which dialect we are in. In this answer, we will recap the Spring format, build the three expressions one field at a time, check them with CronExpression, and compare Spring cron with Unix and Quartz cron.
1A Quick Recap of Spring's Cron Format
A Spring cron expression has six fields separated by spaces, in this order: second (0-59), minute (0-59), hour (0-23), day of month (1-31), month (1-12 or JAN-DEC) and day of week (0-7, where both 0 and 7 mean Sunday, or MON-SUN). A field can be a single value, a list such as 1,15, a range such as 9-17, a step such as */15 (every 15 starting at 0) or 10/15 (every 15 starting at 10), or * for every value.
Since Spring Framework 5.3, the parser also understands L for 'last' (last day of the month, or the last Friday with 5L or FRIL), W for 'nearest weekday' (15W), # for 'the nth weekday' (FRI#2, the second Friday) and macros such as @daily and @hourly. Expressions are evaluated in the server's time zone unless @Scheduled sets zone.
| Position | Field | Allowed values |
|---|---|---|
| 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 | 0-7 (0 and 7 are Sunday) or MON-SUN, L, #, ? |
2Every Weekday at 06:30
We read the requirement field by field. Second 0, minute 30, hour 6, any day of month, any month, and Monday to Friday in the day-of-week field.
Notice the leading 0 for seconds. Without it, "30 6 * * MON-FRI" has five fields and Spring rejects it at startup with an error that a cron expression must consist of 6 fields. The names MON-FRI are easier to read than 1-5 and avoid any doubt about which number means Sunday.
3Every 15 Minutes During Business Hours
For the minute field, */15 means 0, 15, 30 and 45. For the hour field, 9-17 means every hour from 9 to 17 inclusive. Combined, that is every quarter hour in each of those hours.
The detail that catches people is that 9-17 includes the whole of hour 17, so the expression runs at 17:15, 17:30 and 17:45 too. If 'business hours 9-17' means the last run at 17:00, we need two expressions, and @Scheduled is repeatable, so we can put both on the method. Adding MON-FRI is worth considering too, because business hours rarely include weekends.
4The Last Day of Every Month at 23:00
Months have 28 to 31 days, so no fixed number works. In older Spring versions people scheduled a job daily and checked 'is tomorrow the first?' in code. Since Spring 5.3, L in the day-of-month field means the last day of the month.
Testing expressions with CronExpression.parse(...).next(...) like this is the most useful habit with cron: a unit test that asserts the next few times documents what the expression means and catches a shifted field before production does.
5How Spring Cron Differs From Unix and Quartz Cron
Unix crontab has five fields, starting with minutes, so it cannot schedule to the second. The weekday expression above would be 30 6 * * 1-5 in a crontab. Kubernetes CronJobs use the same five-field format. Many Unix cron implementations do not support L or W, although some do.
Quartz cron starts with seconds like Spring, but it requires a ? in either the day-of-month or the day-of-week field, meaning 'no specific value', because specifying both is not supported. It numbers days of the week 1-7 with 1 as Sunday, which differs from Spring's 0-7, so numeric weekdays copied from one to the other are off by one; names avoid the problem. Quartz also allows an optional seventh field for the year. Our expressions in Quartz would be 0 30 6 ? * MON-FRI and 0 0 23 L * ?.
| Schedule | Spring | Unix / Kubernetes | Quartz |
|---|---|---|---|
| Weekdays 06:30 | 0 30 6 * * MON-FRI | 30 6 * * 1-5 | 0 30 6 ? * MON-FRI |
| Every 15 min, 9-17 | 0 */15 9-17 * * * | */15 9-17 * * * | 0 0/15 9-17 * * ? |
| Last day, 23:00 | 0 0 23 L * * | not standard | 0 0 23 L * ? |
6Follow-up questions
What does ? mean in a Spring cron expression?
Spring accepts ? in the day-of-month and day-of-week fields as a synonym for *, mainly so Quartz-style expressions can be used without editing. In Quartz it is required in one of the two fields; in Spring it is optional.
How do I disable a cron task without removing the code?
Take the expression from configuration, cron = "${jobs.digest.cron}", and set the property to "-", which Spring treats as a disabled trigger. That lets one environment turn a job off without a new build.
Does a cron schedule use the server's time zone?
Yes, unless we set the zone attribute of @Scheduled. Setting it explicitly, for example zone = "Europe/London", makes the schedule independent of how the server or container was configured.
7Conclusion
In this answer, we wrote the three schedules in Spring's six-field cron format: 0 30 6 * * MON-FRI for weekdays at 06:30, 0 */15 9-17 * * * for every quarter hour from 09:00 to 17:45, with two expressions if the last run must be 17:00, and 0 0 23 L * * for 23:00 on the last day of each month, using L from Spring 5.3. We checked each with CronExpression.next(), and saw that Unix cron has five fields without seconds, while Quartz cron needs a ? in a day field, numbers weekdays from Sunday as 1 and allows a year.
Open with
Spring cron has six fields: second, minute, hour, day of month, month and day of week. Every weekday at 06:30 is 0 30 6 star star MON-FRI. Every 15 minutes during business hours is 0, then star slash 15 for the minutes, 9 dash 17 for the hours, and three stars.
Then, if they want more
One detail: 9 to 17 includes the whole of hour 17, so the last run is 17:45; if it has to stop at 17:00, I'd use two @Scheduled annotations, 9 to 16 every 15 minutes plus 0 0 17, and probably restrict both to weekdays.
The last day of the month at 23:00 is 0 0 23 L star star; Spring has supported L, W and the hash syntax since 5.3, so February 2026 gives the 28th. I always check expressions with CronExpression.parse and next in a unit test, because a shifted field still parses and means something else.
The differences: Unix cron and Kubernetes CronJobs have five fields with no seconds, so the weekday one is 30 6 star star 1-5. Quartz also starts with seconds, but needs a question mark in either day-of-month or day-of-week, numbers weekdays 1 to 7 starting with Sunday, and allows an optional year field.
I also set zone on @Scheduled so the server's default time zone doesn't matter.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Spring Framework 5
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Spring Batch reference
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Write Spring cron expressions for: every weekday at 06:30, every 15 minutes during...": https://scrivio-interview-library.netlify.app/spring-boot/scheduling/57fb584bc7/