Home / Developer Tool Guides / Cron Expression Guide

Cron Expression Complete Guide

From zero to mastery: master Cron's seven-field structure, special character syntax, high-frequency presets, cross-platform comparison, error troubleshooting, and security best practices in one article.

~10 min read Updated 2026-06-16 TudoSi Tools Team
Try the Cron Expression Generator Now
Visually configure second/minute/hour/day/month/week/year fields with real-time preview of next 7 execution times. Supports multi-standard switching. All operations run locally in your browser.
Open Tool
#01

What Is a Cron Expression? Origin & Core Concepts

A Cron Expression is a string format for defining when scheduled tasks should execute. The name derives from Greek chronos (time). It originated in 1975 as part of Unix V7's cron daemon—a background service that runs commands on a schedule.

Cron's core idea: one string precisely describes "when to run". The standard format consists of 6 or 7 space-separated fields: sec min hour day mon week [year]. Each field can be a literal value (5), range (1-5), list (1,3,5), interval (0/15), or wildcard (*).

Today, Cron has transcended its Unix origins to become a cross-language, cross-framework standard for scheduling. Java Quartz, Spring Schedule, Node.js node-cron, Go robfig/cron and other major libraries all adopt or are compatible with Cron syntax. Understanding Cron expressions is an essential skill for backend developers configuring scheduled tasks.

#02

Seven-Field Structure Deep-Dive: Field Meanings & Value Ranges

FieldNameRangeAllowed Chars
#1Second0-59* , - /
#2Minute0-59* , - /
#3Hour0-23* , - /
#4DayOfMonth1-31* , - / ? L W C
#5Month1-12* , - /
#6DayOfWeek1-7 (varies)* , - / ? L #
#7(optional)Year1970-2099* , - /

Key rule: Day-of-month (#4) and Day-of-week (#6) cannot both have concrete values—one must use ? to mean "unspecified". This is one of the most common mistakes beginners make.

In the Cron Generator tool, you can select each field's value via tabs; the system automatically handles day/week conflicts and generates valid expressions.

#03

Special Characters & Advanced Syntax: L, W, C, # Usage Guide

Beyond basic wildcards and ranges, Cron provides special characters for expressing complex time semantics:

  • L (Last) — Last day/week: In day-of-month means last day of month (e.g., L = month-end). In day-of-week means Saturday (e.g., 6L = last Friday of month). Note: LW can be combined.
  • W (Weekday) — Nearest weekday: Day-of-month only. Specifies the nearest weekday (Mon-Fri) to the target date. E.g., 15W means nearest weekday to the 15th. If the 15th is Saturday, it matches the 14th (Friday); if Sunday, it matches the 16th (Monday).
  • ? (Unspecified) — No specific value: Day-of-month and day-of-week only. Functionally equivalent to * but semantically clearer—"I don't care about this dimension". The standard way to resolve day/week conflict.
  • # (Nth) — Nth weekday of month: Day-of-week only. E.g., 3#2 = 2nd Tuesday of month. 6#3 = 3rd Friday of month. Supported by Quartz and Spring.
  • C (Calendar) — Calendar-dependent: Quartz-specific. Computes values relative to a parent calendar. Rarely used.

Availability of these characters varies by implementation. Our tool automatically suggests available special characters based on the selected standard.

#04

7 High-Frequency Presets: From Daily Backups to CI/CD Triggers

Use CaseExpressionMeaning
Daily DB backup at 2 AM0 0 2 * * ?Every day at 02:00:00
Weekday report at 9 AM0 0 9 ? * MON-FRIMon-Fri at 09:00:00
Monthly cache cleanup on 1st0 0 0 1 * ?1st of each month at 00:00:00
Health check every 15 min0 */15 * * * ?:00/:15/:30/:45 each hour
Month-end settlement0 0 18 LW * ?Last workday of month at 18:00
CI/CD poll every 5 min0 */5 * * * *Check every 5 minutes
Annual report on Jan 10 0 10 1 1 ?Jan 1st each year at 10:00

All presets can be selected directly in the Cron Generator's preset list—click to view parsing results and upcoming execution time preview.

#05

Cross-Platform Differences: Linux Crontab vs Spring vs Quartz

Although all called "Cron", implementations differ significantly across platforms:

FeatureLinux CrontabSpring ScheduleQuartz
Field count5 or 6 (no seconds)6 or 76 or 7
Sunday value0 or 71=Sun (MON-FRI=2-6)1=Sun or SUN-SAT
Supports L/W/#NoL/W/CL/W/#/C
Year fieldNoOptional (7th)Optional (7th)
? constraintN/ADay/week must use ?Same as Spring

Practical tip: When copying from Linux crontab to Spring, prepend a seconds field (add 0 at front) and adjust Sunday values (subtract 1, change 0 to 7). Our tool provides standard switching in the top-right corner for one-click conversion.

#06

Common Error Troubleshooting: 5 Most Frequent Pitfalls & Fixes

  1. Both day and week specified → Error or no execution
    Wrong: 0 0 12 15 * 1 (15th AND Monday)
    Fix: 0 0 12 ? * 1 (every Monday) or 0 0 12 15 * ? (15th of each month)
  2. Sunday=0 in Spring → Becomes Monday
    Reason: Spring uses 1=Sunday; 0 is invalid
    Fix: Change week field 0→1, or remap entire 1-7 range
  3. */5 starting from non-zero? → Use n/m format
    Need: Every 5 min starting from minute 3
    Wrong: */5 (actually starts from 0)
    Fix: 3/5 (start at min 3, interval 5)
  4. Missing seconds when copying Linux expr to Spring
    Linux: 0 2 * * * (daily at 2 AM)
    Spring needs: 0 0 2 * * ? (prepend seconds, append ?)
  5. L+W combination edge cases
    LW rolls back to nearest weekday at month-end on weekends, but "nearest" definition may vary slightly across frameworks. Always verify with the tool preview.
#07

Summary: Monitoring & Ops Tips for Cron in Production

Cron expressions themselves contain no sensitive information, but the tasks they describe often involve critical business processes: database backup windows, key rotation schedules, log archiving strategies, payment reconciliation timing, etc. Leaking these time rules could help attackers infer system operation patterns.

This tool's core design principle is "100% frontend-only operation". All Cron expression generation, parsing, and execution time preview calculations happen locally in your browser. The tool never sends your time rules or business context to any server, nor does it save your configuration history anywhere.

For scenarios involving sensitive scheduling info (production environment task configs, batch processing times involving financial operations, etc.), we recommend using this tool in fully offline or controlled network environments, or manually redacting key parameters before pasting into the input field. Security matters—cautious handling is always the right choice.