Date/Time
ISO 8601 Date-Time Regex
APIs and log systems usually exchange timestamps as ISO 8601 date-times, for example 2026-11-30T14:05:00Z or 2026-11-30T09:30+05:00. This pattern requires the date, a capital T, hours and minutes, and then allows optional seconds, up to nine fractional digits and a trailing Z or numeric offset. It suits webhook payload checks, configuration files, CSV imports and log parsers. Hours are limited to 00 through 23. The honest limit is that leap seconds and the 24:00 end-of-day form are rejected, and impossible calendar dates such as 30 February still match.
Pattern (JavaScript)
/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])T([01][0-9]|2[0-3]):[0-5][0-9](:[0-5][0-9](\.[0-9]{1,9})?)?(Z|[+-]([01][0-9]|2[0-3]):?[0-5][0-9])?$/Starts at the start of the line/string, then a digit, exactly 4 times, then the character "-", then a group (the character "0", then one of the characters 1-9 OR the character "1", then one of the characters 0-2), then the character "-", then a group (the character "0", then one of the characters 1-9 OR one of the characters 12, then a digit OR the character "3", then one of the characters 01), then the character "T", then a group (one of the characters 01, then a digit OR the character "2", then one of the characters 0-3), then the character ":", then one of the characters 0-5, then a digit, then a group (the character ":", then one of the characters 0-5, then a digit, then a group (the character ".", then a digit, between 1 and 9 times), optionally (zero or one time)), optionally (zero or one time), then a group (the character "Z" OR one of the characters +-, then a group (one of the characters 01, then a digit OR the character "2", then one of the characters 0-3), then the character ":", optionally (zero or one time), then one of the characters 0-5, then a digit), optionally (zero or one time), then the end of the line/string.
Limit: Checks the format only; it does not check calendar validity like 31 February or leap years.
Examples
Matches
- ✓ 2026-11-30T14:05:00Z
- ✓ 2026-11-30T09:30+05:00
- ✓ 2026-11-30T23:59:59.123Z
Does not match
- ✗ 2026-11-30 14:05
- ✗ 2026-11-30T24:00:00Z
- ✗ 2026-11-30T14:5Z
Try it
0 matches (JavaScript engine)
2026-11-30T14:05:00Z
2026-11-30T09:30+05:00
2026-11-30T23:59:59.123Z
2026-11-30 14:05
2026-11-30T24:00:00Z
2026-11-30T14:5ZCode in 8 languages
Converted automatically from the JavaScript pattern; language-specific notes are shown where the syntax or support differs.
JavaScript
const re = /^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])T([01][0-9]|2[0-3]):[0-5][0-9](:[0-5][0-9](\.[0-9]{1,9})?)?(Z|[+-]([01][0-9]|2[0-3]):?[0-5][0-9])?$/g;
const text = "2026-11-30T14:05:00Z";
const matches = [...text.matchAll(re)].map((m) => m[0]);
console.log(matches);Python
import re
pattern = re.compile(r'^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])T([01][0-9]|2[0-3]):[0-5][0-9](:[0-5][0-9](\.[0-9]{1,9})?)?(Z|[+-]([01][0-9]|2[0-3]):?[0-5][0-9])?$')
text = '2026-11-30T14:05:00Z'
matches = [m.group(0) for m in pattern.finditer(text)]
print(matches)PHP
<?php
$pattern = '/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])T([01][0-9]|2[0-3]):[0-5][0-9](:[0-5][0-9](\.[0-9]{1,9})?)?(Z|[+-]([01][0-9]|2[0-3]):?[0-5][0-9])?$/';
$text = '2026-11-30T14:05:00Z';
preg_match_all($pattern, $text, $matches);
print_r($matches[0]);Java
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Main {
public static void main(String[] args) {
Pattern pattern = Pattern.compile("^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])T([01][0-9]|2[0-3]):[0-5][0-9](:[0-5][0-9](\\.[0-9]{1,9})?)?(Z|[+-]([01][0-9]|2[0-3]):?[0-5][0-9])?$");
String text = "2026-11-30T14:05:00Z";
Matcher matcher = pattern.matcher(text);
while (matcher.find()) {
System.out.println(matcher.group());
}
}
}Go
package main
import (
"fmt"
"regexp"
)
func main() {
re := regexp.MustCompile(`^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])T([01][0-9]|2[0-3]):[0-5][0-9](:[0-5][0-9](\.[0-9]{1,9})?)?(Z|[+-]([01][0-9]|2[0-3]):?[0-5][0-9])?$`)
text := "2026-11-30T14:05:00Z"
fmt.Println(re.FindAllString(text, -1))
}C#
using System;
using System.Text.RegularExpressions;
var pattern = new Regex(@"^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])T([01][0-9]|2[0-3]):[0-5][0-9](:[0-5][0-9](\.[0-9]{1,9})?)?(Z|[+-]([01][0-9]|2[0-3]):?[0-5][0-9])?$");
var text = "2026-11-30T14:05:00Z";
foreach (Match m in pattern.Matches(text))
{
Console.WriteLine(m.Value);
}Rust
// Cargo.toml: regex = "1"
use regex::Regex;
fn main() {
let re = Regex::new(r"^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])T([01][0-9]|2[0-3]):[0-5][0-9](:[0-5][0-9](\.[0-9]{1,9})?)?(Z|[+-]([01][0-9]|2[0-3]):?[0-5][0-9])?$").unwrap();
let text = "2026-11-30T14:05:00Z";
for m in re.find_iter(text) {
println!("{}", m.as_str());
}
}- Add regex = "1" under [dependencies] in Cargo.toml.
Ruby
pattern = /^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])T([01][0-9]|2[0-3]):[0-5][0-9](:[0-5][0-9](\.[0-9]{1,9})?)?(Z|[+-]([01][0-9]|2[0-3]):?[0-5][0-9])?$/
text = '2026-11-30T14:05:00Z'
matches = text.to_enum(:scan, pattern).map { Regexp.last_match[0] }
p matchesFrequently asked questions
- Why is the timezone optional?
- ISO 8601 allows local times without an offset, but such values are ambiguous across regions. If your system needs absolute times, make the final group mandatory by removing its question mark.
- Does this accept a space instead of T?
- No. RFC 3339 permits a space in some contexts, but strict ISO 8601 uses T. Change T to [T ] if you need to accept both forms.
- How many fractional digits are allowed?
- Between one and nine, which covers milliseconds, microseconds and nanoseconds. JavaScript's toISOString produces exactly three.