Regex for ISO 8601 DateTime
Matches ISO 8601 datetime strings with timezone. Example: 2026-03-15T14:30:00Z or 2026-03-15T14:30:00+05:30.
Pattern
/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$/Pattern Breakdown
| Token | Explanation |
|---|---|
| \d{4}-\d{2}-\d{2} | Date in YYYY-MM-DD format |
| T | Literal T separator between date and time |
| \d{2}:\d{2}:\d{2} | Time in HH:MM:SS format |
| (?:\.\d+)? | Optional fractional seconds |
| (?:Z|[+-]\d{2}:\d{2}) | Timezone: Z (UTC) or offset like +05:30 |
Test Examples
| Input | Match? |
|---|---|
| 2026-03-15T14:30:00Z | Match |
| 2026-03-15T14:30:00.123Z | Match |
| 2026-03-15T14:30:00+05:30 | Match |
| 2026-03-15 14:30:00 | No match |
| 2026-03-15 | No match |
Common Use Cases
- API timestamp validation
- Log timestamp parsing
- Date interchange format verification
Variations
^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$UTC only (no offset)
Other Regex Patterns
Want to test this pattern with your own data?
Open the Regex Tester