ISO 8601 Duration Builder

Convert between natural-language durations and ISO 8601 durations (PnYnMnDTnHnMnS) in both directions with validation of edge cases

Bidirectional converter for ISO 8601 durations. Natural language (e.g. "3 years 2 months 14 days", "2h30m", "3天2小时") parses to canonical P3Y2M14D; ISO strings parse back to readable form with per-component breakdown. Validates the tricky ISO 8601 rules (T-section units, weeks not combined with Y/M/D, decimal only on smallest unit, at least one component).

Example Results

2 examples

Convert "3 years 2 months 14 days" to ISO 8601

Natural-language duration parsed into the canonical P3Y2M14D form with component breakdown.

ISO 8601 duration with breakdown.
View input parameters
{ "input": "3 years 2 months 14 days", "direction": "auto" }

Parse an ISO 8601 duration back to words

Paste PT2H30M or P1WT12H and get the readable form plus each component value.

ISO 8601 duration expanded into natural language.
View input parameters
{ "input": "PT2H30M", "direction": "auto" }

Key Facts

Category
Developer & Web
Input Types
text, select
Output Type
html
Sample Coverage
4
API Ready
Yes

Overview

The ISO 8601 Duration Builder is a bidirectional converter that translates between natural-language durations and canonical ISO 8601 duration strings. It validates complex formatting rules, including T-section separators, decimal placements, and component combinations, while providing a detailed breakdown of each time unit.

When to Use

  • When writing configuration files, API payloads, or database schemas that require strict ISO 8601 duration formats.
  • When parsing and debugging complex ISO 8601 duration strings received from external APIs or system logs.
  • When converting user-friendly, natural-language time intervals into standardized machine-readable formats.

How It Works

  • Enter a natural-language duration or an ISO 8601 duration string into the input field.
  • Select the conversion direction, or leave it on Auto to let the tool detect the input format.
  • Review the generated output, which displays the converted format alongside a detailed component breakdown.

Use Cases

Generating standardized duration strings for system configuration files or environment variables.
Translating machine-generated ISO 8601 intervals into human-readable text for application dashboards.
Validating that duration strings comply with strict ISO 8601 standards before saving them to a database.

Examples

1. Convert Natural Language to ISO 8601

Backend Developer
Background
A developer needs to store a user-defined trial period of '3 months and 10 days' in a database that requires ISO 8601 format.
Problem
Manually formatting the duration string risks syntax errors, especially with the P and T designators.
How to Use
Type '3 months 10 days' into the input field and set the direction to 'Natural language → ISO 8601'.
Example Config
Input: '3 months 10 days', Direction: 'nl2iso'
Outcome
The tool outputs the canonical ISO 8601 duration string 'P3M10D' along with a breakdown of the components.

2. Parse ISO 8601 Duration to Human-Readable Text

Product Manager
Background
A product manager is reviewing API logs containing duration values like 'PT4H30M' and needs to quickly verify the exact time interval.
Problem
Reading raw ISO 8601 strings can be slow and error-prone when scanning multiple logs.
How to Use
Paste 'PT4H30M' into the input field and set the direction to 'ISO 8601 → Natural language'.
Example Config
Input: 'PT4H30M', Direction: 'iso2nl'
Outcome
The tool displays the human-readable translation '4 hours 30 minutes' alongside its individual components.

Try with Samples

development

Related Hubs

FAQ

What is the basic format of an ISO 8601 duration?

It follows the pattern PnYnMnDTnHnMnS, where P is the duration designator, Y/M/D represent date units, T is the time designator, and H/M/S represent time units.

Can I mix weeks with other units in ISO 8601?

No, standard ISO 8601 rules state that weeks (W) should not be combined with other date or time units like years, months, or days.

Where can decimal fractions be used in a duration string?

Decimals are only permitted on the smallest, final unit present in the duration string, such as PT1.5H or PT1H30.5M.

What does the 'T' designator signify in the duration string?

The 'T' designator separates date units (Years, Months, Days) from time units (Hours, Minutes, Seconds) to prevent ambiguity between Months (M) and Minutes (M).

Does this tool support negative durations?

The tool validates standard ISO 8601 duration components and outputs canonical positive intervals based on the input provided.

API Documentation

Request Endpoint

POST /en/api/tools/iso-8601-duration-builder

Request Parameters

Parameter Name Type Required Description
input text Yes -
direction select No -

Response Format

{
  "result": "
Processed HTML content
", "error": "Error message (optional)", "message": "Notification message (optional)", "metadata": { "key": "value" } }
HTML: HTML

AI MCP Documentation

Add this tool to your MCP server configuration:

{
  "mcpServers": {
    "elysiatools-iso-8601-duration-builder": {
      "name": "iso-8601-duration-builder",
      "description": "Convert between natural-language durations and ISO 8601 durations (PnYnMnDTnHnMnS) in both directions with validation of edge cases",
      "baseUrl": "https://elysiatools.com/mcp/sse?toolId=iso-8601-duration-builder",
      "command": "",
      "args": [],
      "env": {},
      "isActive": true,
      "type": "sse"
    }
  }
}

You can chain multiple tools, e.g.: `https://elysiatools.com/mcp/sse?toolId=png-to-webp,jpg-to-webp,gif-to-webp`, max 20 tools.

If you encounter any issues, please contact us at [email protected]