Aarunya AppsAarunya Apps

ISO 8601 TimestampRegex — Pattern, Examples & Code

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

What it matches / doesn't match

Matches ✅Does not match ❌
2024-01-15T09:30:00Z2024-01-15 09:30:00
2024-06-01T12:00:00.123+05:302024-01-15T09:30:00
1999-12-31T23:59:59.999999999Znot-a-timestamp

How it works

Matches ISO 8601 combined date-time strings with a required timezone designator. Fractional seconds (up to 9 digits for nanosecond precision) are optional. The timezone must be either 'Z' for UTC or an explicit +HH:MM / -HH:MM offset. Dates without a time component are not matched by this pattern.

Code Usage

JavaScript

const regex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{1,9})?(Z|[+-]\d{2}:\d{2})$/;
regex.test("2024-01-15T09:30:00Z"); // true

Python

import re
pattern = re.compile(r'^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{1,9})?(Z|[+-]\d{2}:\d{2})$')
bool(pattern.match("2024-01-15T09:30:00Z"))  # True

Go

import "regexp"
r := regexp.MustCompile(`^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{1,9})?(Z|[+-]\d{2}:\d{2})$`)
r.MatchString("2024-01-15T09:30:00Z") // true

Need a custom regex for a different use case?

Generate a custom regex with AI →

FAQ

What does the ISO 8601 Timestamp regex pattern match?

Matches ISO 8601 combined date-time strings with a required timezone designator. Fractional seconds (up to 9 digits for nanosecond precision) are optional. The timezone must be either 'Z' for UTC or an explicit +HH:MM / -HH:MM offset. Dates without a time component are not matched by this pattern.

How do I use the ISO 8601 Timestamp regex in JavaScript?

const regex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{1,9})?(Z|[+-]\d{2}:\d{2})$/; regex.test("2024-01-15T09:30:00Z"); // true

Can I use the ISO 8601 Timestamp regex in Python?

Yes. import re pattern = re.compile(r'^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{1,9})?(Z|[+-]\d{2}:\d{2})$') bool(pattern.match("2024-01-15T09:30:00Z")) # True