# parse-duration

> Convert a human readable duration string to a duration format

Latest version **2.1.8** (published 2026-07-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install parse-duration
pnpm add parse-duration
yarn add parse-duration
bun add parse-duration
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; recently updated; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 2.1.8 |
| Published | 2026-07-10 |
| First published | 2013-12-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 9.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 347 |
| Author | Jake Rosoman |
| Maintainers | jkroso, dfcreative, dy |
| Keywords | parse, duration, time |

## Links

- npm: https://www.npmjs.com/package/parse-duration
- Repository: https://github.com/jkroso/parse-duration
- Homepage: https://github.com/jkroso/parse-duration#readme
- Issues: https://github.com/jkroso/parse-duration/issues
- npm.io page: https://npm.io/package/parse-duration

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 2.1.8 (latest) — 2026-07-10
- 2.1.7 — 2026-07-10
- 2.1.6 — 2026-04-07
- 2.1.5 — 2025-12-21
- 2.1.4 — 2025-03-28
- 2.1.3 — 2025-02-11
- 2.1.2 — 2025-01-31
- 2.1.1 — 2025-01-31
- 2.1.0 — 2025-01-31
- 2.0.2 — 2025-01-31
- 2.0.1 — 2025-01-26
- 2.0.0 — 2025-01-26
- 1.1.2 — 2025-01-24
- 1.1.1 — 2024-12-01
- 1.1.0 — 2023-06-06
- … 20 more at https://npm.io/package/parse-duration/versions

## README

# parse-duration [![Test](https://github.com/jkroso/parse-duration/actions/workflows/test.yml/badge.svg)](https://github.com/jkroso/parse-duration/actions/workflows/test.yml)

Convert a human readable duration to ms.

[![NPM](https://nodei.co/npm/parse-duration.png?mini=true)](https://npmjs.org/package/parse-duration)

## Usage

```js
import parse from 'parse-duration'

// parse different time units
let ns = parse('1ns')       // => 1 / 1e6
let μs = parse('1μs')       // => 1 / 1000
let ms = parse('1ms')       // => 1
let s = parse('1s')         // => ms * 1000
let m = parse('1m')         // => s * 60
let h = parse('1h')         // => m * 60
let d = parse('1d')         // => h * 24
let w = parse('1w')         // => d * 7
let mo = parse('1mo')       // => y / 12
let y = parse('1y')         // => d * 365.25

// compound expressions
parse('1hr 20mins')         // => 1 * h + 20 * m
parse('1 hr 20 mins')       // => 1 * h + 20 * m

// youtube format
parse('1h20m0s')            // => 1 * h + 20 * m

// comma seperated numbers
parse('27,681 ns')          // => 27681 * ns

// noisy input
parse('duration: 1h:20min') // => 1 * h + 20 * m

// negatives
parse('-1hr 40mins')        // => -1 * h - 40 * m

// exponents
parse('2e3s')               // => 2000 * s

// custom output format
parse('1hr 20mins', 'm')    // => 80

// add units
parse.unit['μs'] = parse.unit.microsecond
parse('5μs')                // => 0.005
```

## Locales

Switch the default en locale to another language ([see /locale](/locale)).

```js
import es from 'parse-duration/locale/es.js'
import parse from 'parse-duration'

parse.unit = es

parse('1 hora 20 minutos', 'm') // 80
```


## Safety

In sensitive APIs make sure input string is reasonably short (under 100 characters).



<p align="center"><a href="https://github.com/krishnized/license">ॐ</a></p>

---
_Source: https://npm.io/package/parse-duration · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
