regexhelper
Test a pattern. Copy a ready-made one. No signup.

Regex to Match an ISO 8601 Date-Time

Copy the pattern, paste timestamps, and watch each ISO 8601 date-time light up. Below: what each field means and how the timezone part works.

/ /

What this pattern matches

It matches an ISO 8601 date-time: YYYY-MM-DD, a literal T, then HH:MM:SS, an optional fractional part, and an optional timezone of Z or ±HH:MM.

Part by part

\d{4}-\d{2}-\d{2} — the calendar date.

T\d{2}:\d{2}:\d{2} — the time separator and clock time.

(?:\.\d+)? — optional milliseconds/microseconds.

(?:Z|[+-]\d{2}:\d{2})? — optional UTC marker or numeric offset.

Note on validity

This pattern checks shape, not calendar validity — it will accept 2026-13-40. To confirm a real date, parse it (e.g. new Date(str)) after the pattern matches.

FAQ

Does it require the timezone?

No. The Z or ±HH:MM part is optional, so 2026-09-17T12:30:00 matches too.

Does it match milliseconds?

Yes, the (?:\.\d+)? group accepts a dot followed by any number of fractional digits.

Will it reject an impossible date like month 13?

No. It validates format, not calendar range. Parse the string afterwards to confirm it is a real date.