Skip to main content
Regexflux

ISO 8601 DateTime

intermediate

Matches full ISO 8601 datetime strings including time and timezone.

datetimeisotimestamptimezone

Pattern

/\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])T(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d(?:\.\d+)?(?:Z|[+-](?:[01]\d|2[0-3]):[0-5]\d)/g

Try It

0 of 6 strings matched

Explanation

Matches a full ISO 8601 datetime: date (YYYY-MM-DD), literal T, time (HH:MM:SS), optional fractional seconds, and timezone (Z for UTC or ±HH:MM offset).

Test Strings

Matching

  • 2024-01-15T09:30:00Z
  • 2023-12-31T23:59:59.999+05:30
  • 2024-06-15T12:00:00-04:00

Non-matching

  • 2024-01-15
  • 2024-01-15 09:30:00
  • 2024-13-01T00:00:00Z

Language Compatibility

LanguageSupport
JSFull support
PYTHONFull support
JAVAFull support
PHPFull support
GOFull support

Code Snippets

const regex = /\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])T(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d(?:\.\d+)?(?:Z|[+-](?:[01]\d|2[0-3]):[0-5]\d)/g;
const text = "your text here";
const matches = text.match(regex);
console.log(matches);

Common Variations

Without timezone

\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])T(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d

Local datetime without timezone offset

Related Patterns