ISO 8601 Date-Time in JS
Match full ISO 8601 date-times with timezone offset or Z suffix (e.g. 2024-01-15T14:30:00Z).
Try it in the JS tester →Pattern
regexJS
\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+\-]\d{2}:?\d{2}) (flags: g)JavaScript / ECMAScript code
jsJavaScript
const re = new RegExp("\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(?:\\.\\d+)?(?:Z|[+\\-]\\d{2}:?\\d{2})", "g");
const input = "2024-01-15T14:30:00Z";
const matches = [...input.matchAll(re)];
console.log(matches.map(m => m[0]));Uses `String.prototype.matchAll` for global iteration (Node 12+ / all modern browsers).
How the pattern works
Date YYYY-MM-DD, literal T, time HH:MM:SS, optional fractional seconds, then either Z or a ±HH:MM / ±HHMM offset.
Examples
Input
2024-01-15T14:30:00ZMatches
2024-01-15T14:30:00Z
Input
2024-03-01T09:00:00.123+05:30Matches
2024-03-01T09:00:00.123+05:30
Input
2024-01-15No match
—