Run a Quartz job every Saturday and Sunday at midnight
The Quartz expression for “Every weekend day” is 0 0 0 ? * 1,7. Below: config you can paste, the next run times, and what to watch out for. Quartz CronTrigger takes six or seven fields, seconds first, with Sunday as 1 and ? in one day field.
0 0 0 ? * 1,7Open in tool“At 00:00, only on Sunday and Saturday”
CronTrigger
CronTrigger
Trigger trigger = TriggerBuilder.newTrigger()
.withIdentity("every-weekend")
.withSchedule(CronScheduleBuilder.cronSchedule("0 0 0 ? * 1,7")
.inTimeZone(TimeZone.getTimeZone("UTC")))
.build();Quartz gotchas
One day field must be ?Quartz does not support setting both day of month and day of week. Put ? in the one you do not use.
Sunday is 1Day of week runs 1-7 from SUN, so 2-6 is Monday to Friday. A crontab 1-5 means something else here.
MisfiresIf the scheduler is down at fire time, the misfire instruction decides what happens. The default fires once as soon as it can.
The year is optionalA seventh field limits the years. Leave it out to run every year.
FAQ
What is the Quartz cron expression for “Every weekend day”?
0 0 0 ? * 1,7. It reads: At 00:00, only on Sunday and Saturday
Which time zone does a Quartz schedule use?
In the JVM’s default time zone, unless you call inTimeZone() on the CronScheduleBuilder.
Is Quartz cron the same as Spring cron?
No. Both start with seconds, but Quartz counts Sunday as 1 and needs ? in one day field; Spring counts Sunday as 0 and has no year field.
What does L mean in Quartz?
In day of month, L is the last day of the month. In day of week, 6L is the last Friday, and L alone means Saturday.