isIso8601Time.php
Table of Contents
Functions
- isIso8601Time() : bool
- Validates whether a string is a valid ISO 8601 time format.
Functions
isIso8601Time()
Validates whether a string is a valid ISO 8601 time format.
isIso8601Time(string $time[, bool $strict = false ]) : bool
This function checks if a given string conforms to the ISO 8601 time specification. ISO 8601 time format includes:
- Optional 'T' prefix
- Hours (00-23)
- Optional minutes (00-59)
- Optional seconds (00-59, can be fractional)
- Optional timezone offset (Z for UTC or ±HH:MM)
Examples of valid formats:
- "T14:30:00Z" → 14:30:00 UTC
- "T08:15:30+02:00" → 08:15:30 in UTC+2
- "T23:59:59" → 23:59:59 local time (no offset)
Rules:
- Hours must be 00-23
- Minutes and seconds, if present, must be 00-59
- Fractional seconds are allowed
- Timezone, if present, must be 'Z' or ±HH:MM
Parameters
- $time : string
-
The time string to validate
- $strict : bool = false
-
If true, validates strictly with regex; if false, uses DateTimeImmutable parser (default: false)
Tags
Return values
bool —True if the string is a valid ISO 8601 time, false otherwise