Cron explainer › Examples

Cron expression for every hour (on the hour)

Every hour, on the hour

SyntaxExpression
Unix crontab 0 * * * *
Spring @Scheduled 0 0 * * * *
Quartz 0 0 * * * ?

Open and edit in the explainer →

Tip When many servers call an external API at exactly :00, requests pile up. Spread them out with a different minute (for example :07).

Next run times (UTC)

  1. Calculating…

Configuration examples

crontab

# crontab -e
0 * * * * /path/to/script.sh >> /var/log/job.log 2>&1

Runs in the server's system time zone. Check it with timedatectl.

Spring

@Scheduled(cron = "0 0 * * * *", zone = "UTC")
public void runJob() {
    // ...
}

Requires @EnableScheduling. Without zone, the server time zone is used.

Quartz

Trigger trigger = TriggerBuilder.newTrigger()
    .withIdentity("myTrigger")
    .withSchedule(CronScheduleBuilder.cronSchedule("0 0 * * * ?")
        .inTimeZone(TimeZone.getTimeZone("UTC")))
    .build();

Quartz always needs "?" in either day-of-month or day-of-week.

Kubernetes

apiVersion: batch/v1
kind: CronJob
metadata:
  name: my-job
spec:
  schedule: "0 * * * *"
  timeZone: "UTC"
  jobTemplate:
    spec:
      template:
        spec:
          restartPolicy: OnFailure
          containers:
            - name: job
              image: busybox
              command: ["sh", "-c", "echo hello"]

The timeZone field is GA since Kubernetes 1.27. Without it, the kube-controller-manager time zone (usually UTC) is used.

GitHub Actions

on:
  schedule:
    - cron: '0 * * * *'  # UTC

GitHub Actions always runs in UTC. Convert from UTC before using this.

More cron examples

Every minuteEvery 5 minutesEvery 10 minutesEvery 15 minutesEvery 30 minutesEvery 2 hoursEvery 6 hoursEvery day at midnightEvery day at 9 AMEvery day at 6 PMTwice a day (9:00 and 18:00)Weekdays at 9 AMEvery 10 minutes during business hoursWeekends at 10 AMEvery Monday at 9 AMEvery Sunday at midnightFirst day of every month15th of every monthLast day of every monthLast weekday of every monthSecond Monday of every monthLast Friday of every monthEvery quarter (Jan, Apr, Jul, Oct 1st)Every year on January 1stEvery 10 secondsEvery 30 seconds