cronkit.org
Cron expressions, explained and converted — in your browser

Cron tools › Platforms

Spring cron expressions

six fields · seconds first · @Scheduled(zone = …)

Paste the cron value of a Spring @Scheduled annotation to see what it means and when it fires in the zone you choose. Convert a Linux crontab line into Spring's six fields, or a Spring expression back into Linux cron.

Next runs

Code

As Linux cron

Convert from Linux cron

Try one

How to check a Spring @Scheduled cron expression

  1. Paste the expression: six fields, starting with seconds. A five-field Linux line is rejected with a hint to add 0 in front.
  2. Pick the zone you will put in @Scheduled(zone = …). The run list and the code use it.
  3. Read the meaning, the field breakdown and the next runs; warnings flag legal-but-suspicious values such as * in the seconds field.
  4. Copy the @Scheduled annotation, or the version that reads the expression from application.properties.
  5. To go the other way, see As Linux cron; to start from a crontab line, use Convert from Linux cron.

Spring's six fields

PositionFieldValues and specials
1second0-59
2minute0-59
3hour0-23
4day of month1-31, L, L-3, LW, 15W
5month1-12
6day of week0-7 (0 and 7 are Sunday) or MON-SUN; 5L (last Friday), FRI#3 (third Friday)

? is accepted and means the same as *; unlike Quartz, Spring does not require it. When both day fields are set, both must match: 0 0 0 1 * MON runs only when the 1st is a Monday. Coming from Quartz? The Quartz converter covers its day numbering.

Macros

MacroSame as
@yearly, @annually0 0 0 1 1 *
@monthly0 0 0 1 * *
@weekly0 0 0 * * 0
@daily, @midnight0 0 0 * * *
@hourly0 0 * * * *

From Linux cron to Spring

Put 0 in front for the seconds and keep the other five fields: 30 9 * * 1-5 becomes 0 30 9 * * 1-5. The trap is the day fields. Linux runs 0 0 1 * 1 on the 1st of the month or on a Monday; Spring would run it only on a Monday that is the 1st. The converter splits such a line into two expressions, one per day field, and checks that together they fire at the same times as the Linux line.

FAQ

Why does Spring reject my five-field cron expression?

Spring's CronExpression needs exactly six fields, seconds first. Add 0 in front: 0 */5 * * * becomes 0 0 */5 * * *.

How do I turn a scheduled method off without deleting it?

Set the cron to "-". It is most useful with a property: @Scheduled(cron = "${app.cron}") and app.cron=- in the environment where the job should not run.

Which time zone does @Scheduled use?

The one you name in zone, for example @Scheduled(cron = "0 0 9 * * *", zone = "Europe/Berlin"). Set it explicitly so the schedule does not depend on where the application happens to run.

Is Sunday 0 or 7 in Spring?

Both. Spring accepts 0-7 with 0 and 7 as Sunday, plus the names MON…SUN.