devkult_
tools29converters34
home/regex/iso-8601-datetime

Regex for ISO 8601 Date-Times

This pattern matches full ISO 8601 timestamps in the RFC 3339 profile that APIs and JSON use: a date, a T, a time with seconds, optional fractional seconds, and a mandatory time zone — Z for UTC or an offset like +02:00. It checks the shape; impossible values like month 13 still need a date parser.

/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$/

How it works, token by token

TokenMeaning
^\d{4}-\d{2}-\d{2}the date: YYYY-MM-DD
Tthe literal separator between date and time
\d{2}:\d{2}:\d{2}the time: hh:mm:ss
(?:\.\d+)?optional fractional seconds (.123 or .123456)
(?:Z|[+-]\d{2}:\d{2})the time zone: Z, or an offset such as +02:00
$end of string

What it matches

✓2026-10-15T09:30:00Z
✓2026-10-15T09:30:00.123Z
✓2026-10-15T09:30:00+02:00
✓2026-10-15T09:30:00.5-05:00
✗2026-10-15
✗2026-10-15T09:30:00
✗2026-10-15 09:30:00Z
✗2026-10-15T09:30Z

Try it live

One candidate per line — the m flag makes the ^ and $ anchors apply to each line. Edit anything; it runs in your browser.

/

Variations

^\d{4}-\d{2}-\d{2}[Tt ]\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:[Zz]|[+-]\d{2}:\d{2})$RFC 3339 also permits a space instead of T, and lowercase t and z
^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:Z|[+-]\d{2}:?\d{2})?$looser ISO 8601: seconds and zone optional, offsets with or without a colon

Language notes

  • JavaScript's Date.parse accepts these strings but treats a date-time with no zone as local time — one more reason to require Z or an offset.

Frequently asked questions

Does this reject invalid dates like 2026-02-30?

No — it checks the format only. Parse the value (new Date(value) in JavaScript, datetime.fromisoformat in Python) and check the result to catch impossible dates.

Why require a time zone?

A timestamp without one is ambiguous — 09:30 where? Requiring Z or an offset makes every value point at one exact instant.

Related patterns

Building something custom? The regex tester gives you live match highlighting for any pattern.