Convert a number in milliseconds to a standard duration string.
Install
npm install format-duration
As of v4 this is an ESM-only package. CommonJS code can require() it on Node 22.12+ (see #201 for why).
Usage
import format from 'format-duration'// or named: import { formatDuration } from 'format-duration'// from CommonJS: const { formatDuration } = require('format-duration')// anything under a second is rounded down to zeroformat(999) // '0:00'// 1000 milliseconds is a secondformat(1000) // '0:01'// 1999 rounds down to 0:01format(1000 * 2 - 1) // '0:01'// 60 seconds is a minuteformat(1000 * 60) // '1:00'// 59 seconds looks like thisformat(1000 * 60 - 1) // '0:59'// 60 minutes is an hour