Cron Expression Documentation

What is Cron?

Cron is a time-based job scheduler used in Unix-like operating systems. A cron expression is a string that defines when a task should run.

Unix Cron Format (5 fields)

┌───────────── minute (0-59)
│ ┌───────────── hour (0-23)
│ │ ┌───────────── day of month (1-31)
│ │ │ ┌───────────── month (1-12)
│ │ │ │ ┌───────────── day of week (0-6, Sun=0)
│ │ │ │ │
* * * * *

Quartz Cron Format (6-7 fields)

Used by Java-based schedulers like Quartz. Adds a seconds field at the beginning and uses 1-7 for day of week (SUN=1).

┌───────────── second (0-59)
│ ┌───────────── minute (0-59)
│ │ ┌───────────── hour (0-23)
│ │ │ ┌───────────── day of month (1-31)
│ │ │ │ ┌───────────── month (1-12)
│ │ │ │ │ ┌───────────── day of week (1-7, SUN=1)
│ │ │ │ │ │
0 * * * * *

Key Differences: Unix vs Quartz

FeatureUnixQuartz
Fields56-7
SecondsNoYes (first field)
Day of Week0-6 (Sun=0)1-7 (Sun=1) or SUN-SAT
? wildcardNoYes (DOM or DOW)

Special Characters

CharacterMeaningExample
*Every value* * * * * = every minute
,List0 9,18 * * * = 09:00 and 18:00
-Range0 9 * * 1-5 = weekdays at 09:00
/Step*/15 * * * * = every 15 min

Common Examples

ExpressionDescription
*/5 * * * *Every 5 minutes
0 * * * *Every hour at :00
0 0 * * *Every day at midnight
0 9 * * 1-5Weekdays at 09:00
0 0 1 * *1st of every month at midnight
0 0 1 1 *Every January 1st at midnight
*/30 9-17 * * 1-5Every 30 min during business hours (Mon-Fri)

Common Mistakes

  • Day of week numbering: In Unix, Sunday = 0. In Quartz, Sunday = 1. Mixing these up shifts your schedule by a day.
  • Forgetting timezone: Cron typically runs in the server's timezone. Always verify which timezone your scheduler uses.
  • Using 6 fields in Unix cron: Standard Unix cron has 5 fields. Adding a seconds field will cause errors on most Unix systems.
  • Month/day ranges: 0 0 31 2 * will never run because February never has 31 days.

Frequently Asked Questions

What is a cron expression?

A cron expression is a string of 5 (Unix) or 6-7 (Quartz) fields separated by spaces that defines a recurring schedule. Each field represents a time unit: minute, hour, day of month, month, and day of week.

What is the difference between Unix and Quartz cron?

Unix cron has 5 fields (minute, hour, day of month, month, day of week). Quartz adds a seconds field at the beginning (6 or 7 fields) and uses 1-7 for day of week (Sunday=1) instead of 0-6 (Sunday=0). Quartz also supports the ? wildcard.

What does */5 * * * * mean?

The expression */5 * * * * means "every 5 minutes". The /5 is a step value that divides the range. So */5 in the minute field means at minutes 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, and 55.

How do I schedule a cron job for weekdays only?

Use 1-5 in the day-of-week field (the 5th field in Unix cron). For example, 0 9 * * 1-5 runs at 09:00 every Monday through Friday.

What timezone does cron use?

By default, cron runs in the server's system timezone. In Kubernetes CronJobs, the timezone defaults to the kube-controller-manager timezone (usually UTC). Always check your platform's documentation and use CronWizard's timezone selector to preview schedules.