DevKitHub

Programming

Duration Converter — Seconds, Minutes, Hours, ISO 8601

Enter a duration in almost any notation — 90s, 1h30m, PT1H30M, 01:30:00 — to see it in every unit, as ISO 8601, and as a readable phrase.

1 hour 30 minutes

Milliseconds
5,400,000
Seconds
5,400
Minutes
90
Hours
1.5
Days
0.0625
Weeks
0.008929

As text

ISO 8601for configs
PT1H30M
Clockhours do not wrap
01:30:00
Readable
1 hour 30 minutes

This tool runs entirely in your browser. Your input is never uploaded, stored or logged.

How it works

Four notations are accepted because those are the four people actually have in hand. A compound form like 1h30m, which is also what Go prints. ISO 8601 like PT1H30M, which is what a config file or an API contract usually wants. A clock like 01:30:00, which is what a media player or a spreadsheet gives you. And a plain number with a unit. Sub-millisecond units are included, because a Go duration or a benchmark result is frequently in microseconds or nanoseconds.

Months and years are the sharp edge and are handled by saying so. ISO 8601 allows P1M and P1Y, and neither has a fixed length: a month is 28 to 31 days and a year is 365 or 366. They are accepted, because refusing outright just sends people to a converter that is silently wrong, but the approximation used is stated on every result rather than folded quietly into the number. For an exact answer the only correct method is to subtract two real dates, and the tool says that.

A bare number with no unit is read as seconds, and that assumption is reported too rather than made silently. Hours in the clock output are not wrapped at 24 — a fifty-hour duration renders as 50:00:00, because it is a length of time and not a time of day, and wrapping it is how a duration gets mistaken for a clock reading.

Common problems

Every example below is run against this tool in our test suite, so what it says here is what the tool actually does.

That is not a duration.

5 fortnights
Why:
The unit is not one of the recognised ones. The parser requires every character to belong to a quantity, so prose that merely contains a number is rejected rather than half-read.
Fix:
Use a supported unit: ns, us, ms, s, m, h, d or w, in full or abbreviated.

That is not a clock duration.

1:60:00
Why:
Minutes and seconds in a clock duration run from 0 to 59. Sixty minutes is an hour, and accepting it would make 1:60:00 and 2:00:00 two spellings of the same value.
Fix:
Write 2:00:00, or use the compound form 1h60m if that is genuinely what you meant.

A duration in months came out wrong.

Why:
A month has no fixed length. Any converter that turns P1M into a number of days has picked one, and it is wrong for most months of the year.
Fix:
For anything where the difference matters, subtract two real dates rather than converting a month count. The approximation used here is stated on every result that involves one.

Frequently asked questions

What does it do with months and years?
Accepts them, converts using 30 and 365 days, and tells you every time that the answer is approximate. A month is 28 to 31 days, so no fixed number is right. For an exact result, subtract two real dates instead.
What happens to a number with no unit?
It is read as seconds, and the result says so. Writing 90ms or 90m removes the guess entirely.
Why does a 50-hour duration show as 50:00:00?
Because it is a length of time, not a time of day. Wrapping the hours at 24 is how a duration gets misread as a clock reading, so the hours keep counting up.

Last updated