Skip to main content

Overview

Zod provides validators for ISO 8601 datetime formats under the z.iso namespace:
  • z.iso.datetime() - ISO 8601 datetime strings
  • z.iso.date() - ISO 8601 date strings (YYYY-MM-DD)
  • z.iso.time() - ISO 8601 time strings (HH:MM:SS)
  • z.iso.duration() - ISO 8601 duration strings
Location in source: ~/workspace/source/packages/zod/src/v4/classic/iso.ts

z.iso.datetime()

Validates ISO 8601 datetime strings with various precision and timezone options.

Basic Usage

Valid Examples (Default)

By default, requires UTC timezone indicator (Z):

Invalid Examples (Default)

Precision Options

Control millisecond precision with the precision option:

No Precision Constraint (Default)

Accepts any number of fractional seconds:

Precision: -1 (No Fractional Seconds)

Requires no fractional seconds:

Precision: 0 (Seconds Only)

Requires seconds but no fractional part:

Precision: 3 (Milliseconds)

Requires exactly 3 digits of fractional seconds:

Precision: 4+ (Custom)

Requires exact number of fractional digits:

Offset Options

Control timezone offset handling with the offset option:

offset: false (Default)

Only accepts UTC timezone (Z):

offset: true

Accepts both UTC (Z) and timezone offsets:

Local Time Option

Allow local time (no timezone indicator) with the local option:

local: false (Default)

Requires timezone indicator:

local: true

Accepts both local time and times with timezone:

Combining local and offset

z.iso.date()

Validates ISO 8601 date strings in YYYY-MM-DD format.

Basic Usage

Valid Examples

Invalid Examples

z.iso.time()

Validates ISO 8601 time strings (HH:MM:SS).

Basic Usage

Valid Examples

Precision Option

Similar to datetime, you can specify precision:

z.iso.duration()

Validates ISO 8601 duration strings.

Basic Usage

Valid Examples

Parameters

All ISO datetime functions accept optional parameters:

DateTimeParams

TimeParams

Examples

API Timestamp Validation

Flexible Timezone Handling

Date Range Validation

Schedule with Time

High-Precision Timestamps

Return Type

All ISO datetime schemas return strings:
The ISO datetime validators perform format validation only. They do not parse the string into a Date object or validate that the date is semantically valid (e.g., they accept “2022-02-30” on some validators). For full date validation including semantic checks, combine with additional refinements or use z.date() with coercion.
When using local: true, be aware that the datetime string does not contain timezone information. This can lead to ambiguity when the string is parsed in different timezones. For unambiguous timestamps, prefer using UTC (Z) or explicit offsets.