PlayTools

Cron fields: minute, hour, day-of-month, month, weekday

視覺化構建和驗證 Cron 計畫任務,並以通俗語言描述計畫內容,生成可直接複製的表達式。

Runs in your browser — nothing you enter is uploaded
* * * * *

every minute

Common presets

Minute(0–59)
*
Hour(0–23)
*
Day of Month(1–31)
*
Month(1–12)
*
Day of Week(0–6)
*

Cron format reference

┌── minute (0–59)
│ ┌── hour (0–23)
│ │ ┌── day of month (1–31)
│ │ │ ┌── month (1–12)
│ │ │ │ ┌── day of week (0–6, Sun=0)
│ │ │ │ │
* * * * *
*Every value
*/nEvery n-th value
a-bRange from a to b
a,b,cSpecific values
1-5Monday to Friday
0 0 * * *Daily at midnight

Cron fields: minute, hour, day-of-month, month, weekday

Cron is five (or six with seconds) independent fields; daylight saving can shift wall-clock triggers—prefer UTC for infra tasks when possible.

Validate expressions in staging; some platforms use quartz extensions incompatible with vanilla cron.

Reading a cron expression

┌───────── minute (0–59)
│ ┌─────── hour (0–23)
│ │ ┌───── day of month (1–31)
│ │ │ ┌─── month (1–12)
│ │ │ │ ┌─ day of week (0–6, Sunday = 0)
│ │ │ │ │
0 9 * * 1-5   → 09:00, Monday to Friday

Each field accepts * (every value), a single number, a list (1,15), a range (9-17) or a step (*/15). The builder writes these for you and shows a plain-English description of the schedule, so you can confirm it before pasting it into crontab or a CI configuration.

Worked examples

  • */15 9-17 * * 1-5 — every 15 minutes from 09:00 to 17:45, weekdays only (the last run is 17:45 because the hour field stops at 17).
  • 30 2 * * 0 — 02:30 every Sunday, a common slot for weekly maintenance.
  • 0 0 1 * * — midnight on the first day of every month, for monthly reports.
  • 0 9,18 * * * — 09:00 and 18:00 every day.
  • 0 0 1 1 * — once a year at midnight on 1 January.

Gotchas that cause missed or duplicate runs

  • Day of month OR day of week: when both fields are restricted, standard cron runs when either one matches. 0 0 13 * 5 runs on every 13th and on every Friday, not only on Friday the 13th.
  • Uneven steps: */7 in the minute field runs at :00, :07 … :56 and then :00 again, leaving a 4-minute gap each hour. Steps only divide evenly when they are factors of 60 (minutes) or 24 (hours).
  • Daylight saving time: in a local time zone, jobs scheduled between 01:00 and 03:00 can be skipped or run twice on the nights the clocks change, depending on the cron implementation. Schedule critical jobs in UTC or outside that window.
  • Time zone of the server: crontab uses the machine’s time zone; GitHub Actions schedules always run in UTC; Kubernetes CronJobs can set an explicit timeZone.
  • Last day of the month: standard cron has no syntax for it. Run daily on the 28th–31st and check in the script whether tomorrow is the 1st.

Cron dialects

  • Standard (Vixie) cron and most Linux systems: the five fields shown here. Many also accept 7 for Sunday and three-letter names (MON, JAN).
  • Quartz (Java) and Spring: six or seven fields, starting with seconds, and ? for “no specific value” in day-of-month or day-of-week.
  • AWS EventBridge: six fields including a year, and one of the two day fields must be ?.
  • GitHub Actions: standard five fields in UTC, with runs no more often than every 5 minutes and possible delays at busy times.

Paste the five-field output from this tool as-is into crontab, GitHub Actions or Kubernetes; for Quartz or EventBridge, add the extra fields their syntax requires.

Making a cron job run reliably

  • Run the command by hand first, as the same user cron will use.
  • Use absolute paths: cron starts jobs with a minimal environment and a short PATH, so commands that work in your shell may not be found.
  • Capture output, e.g. 0 2 * * * /usr/local/bin/backup.sh >> /var/log/backup.log 2>&1, otherwise errors are mailed to a local mailbox nobody reads, or lost.
  • Prevent overlaps for long jobs with a lock, for example flock -n /tmp/backup.lock /usr/local/bin/backup.sh.

In-depth guides

These free tools pair well with this page — open them in a new tab to finish your workflow.

常見問題

什麼是cron表達式?

cron表達式是由5個欄位組成的字串(分鐘、小時、日期、月份、星期),定義了一個週期性計畫。Unix cron、GitHub Actions、雲端調度器等眾多系統使用它在指定時間自動執行任務。

cron中的星號(*)表示什麼?

星號(*)表示「每個值」。例如,分鐘欄位中的*表示「每分鐘」,小時欄位中的*表示「每小時」。它是匹配該位置所有有效值的萬用字元。

如何每15分鐘執行一次任務?

使用步長語法:*/15 * * * *。分鐘欄位中的*/15表示「每隔15分鐘」。同樣,小時欄位中的*/2表示「每2小時」。

cron中0和7都表示星期日嗎?

在標準cron中,星期欄位中的0和7都代表星期日。大多數cron實作都接受這兩個值。星期一為1,星期二為2,以此類推,直至星期六(6)。

cron支援時區嗎?

傳統Unix cron使用伺服器的系統時區。許多現代調度器(如帶時區欄位的Kubernetes CronJob、帶時區屬性的GitHub Actions)支援明確的時區設定。始終確認執行cron任務的伺服器時區。

cron的最小頻率是多少?

標準cron的最小解析度為1分鐘。對於亞分鐘級調度,需要其他機制,如帶睡眠間隔的連續迴圈,或支援秒級的任務調度器(如Java中的Quartz,或某些工具中的6欄位cron)。