Cron expression generator
A cron expression is five fields that tell a scheduler when to run a job: minute, hour, day of month, month and day of week. Type one to read it in plain English, see its next five runs in your time zone, and copy it as a Kubernetes CronJob with the time zone already set.
At 9:00 AM, on Monday through Friday.
- Minute
- 0
- minute 0
- Hour
- 9
- 9:00 AM
- Day of month
- *
- every day
- Month
- *
- every month
- Day of week
- 1-5
- Monday through Friday
Next 5 runs
Working out run times…
Kubernetes CronJob
apiVersion: batch/v1
kind: CronJob
metadata:
name: my-job
spec:
schedule: "0 9 * * 1-5"
timeZone: "UTC"
jobTemplate:
spec:
template:
spec:
containers:
- name: my-job
image: busybox:1.28
command: ["/bin/sh", "-c", "date; echo Hello from the Kubernetes cluster"]
restartPolicy: OnFailure
How to read a cron expression
Read the fields left to right. Each field lists the values it runs on. The job runs when the clock matches every field, with one exception below.
Four symbols do the rest:
*means every value, so a star in the hour field is every hour.,makes a list:0,30in the minute field is on the hour and half past.-makes a range, and both ends count:9-17is 9 AM through 5 PM./sets a step.*/5in the minute field means every fifth minute (0, 5, 10 and so on), so*/5 * * * *runs every 5 minutes. A step counts inside its own field only:*/23in the hour field runs at midnight and 11 PM, not every 23 hours.
Month and day names work too. Use the first three letters, upper or lower case, like mon-fri or jan,jul.
When you set both day fields
This rule trips people up. When both day of month and day of week are set, cron runs on days that match either one, not both. 30 4 1,15 * 5, the example in the crontab(5) manual, doesn't mean "Fridays that fall on the 1st or 15th". It runs at 4:30 AM on the 1st, the 15th and every Friday.
Put a * in either day field and the rule is off: the other field decides alone. And if you only want those Fridays, schedule every Friday and have the job check the date.
Common cron expressions
Cron with 5 or 6 fields
Standard cron, the kind in a crontab and in Kubernetes, has five fields. Quartz, the Java scheduler, uses six or seven: it puts seconds first and an optional year last. To move 0 0 9 * * ? to a 5-field scheduler, drop the leading seconds and write the ? as *: 0 9 * * *. Kubernetes and the tool both read a ? in a day field as a star, but crontab doesn't list it.
Every 5 seconds? Standard cron can't. It checks its schedule once a minute, so a minute is the smallest step. For anything faster, run a loop inside the job.
Run it as a Kubernetes CronJob
A Kubernetes CronJob takes the same five fields in spec.schedule. Three things catch people out:
- The time zone. Without
spec.timeZone, the schedule follows the cluster controller's local time zone. Set it to a name likeAmerica/New_YorkorEtc/UTC. The field is stable since Kubernetes 1.27. - No time zone in the schedule. Kubernetes rejects a schedule that includes a
CRON_TZ=orTZ=time zone. - Sunday is 0. Kubernetes lists day of week as 0 to 6, so write Sunday as 0, not 7.
@hourly, @daily, @weekly, @monthly and @yearly work in both crontab and Kubernetes. Type one into the tool to see the five fields behind it.
Cron and daylight saving time
Daylight saving bites cron jobs twice a year. On the night clocks jump forward, a time in the skipped hour never comes, so cron skips the job. On the night they fall back, a time in the repeated hour comes twice, so cron runs it twice. Our advice: unless a job has to fire at a local clock time, schedule it in UTC. UTC has no daylight saving, so neither can happen.
Run your cron jobs on American Cloud
A schedule needs somewhere to run. On American Cloud, that's a cron entry (or a systemd timer) on your own VM, or a CronJob on our managed Kubernetes, where the first control node is free. Moving off Heroku Scheduler or Vercel cron? Our Heroku and Vercel migration guides cover moving the jobs. And if a job doesn't run when you expected, ask us: our support team's median reply time is under 2 minutes.