
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
format-duration
Advanced tools
Convert a number in milliseconds to a standard duration string.
npm install format-duration
const format = require('format-duration')
// anything under a second is rounded down to zero
format(999) // '0:00'
// 1000 milliseconds is a second
format(1000) // '0:01'
// 1999 rounds down to 0:01
format(1000 * 2 - 1) // '0:01'
// 60 seconds is a minute
format(1000 * 60) // '1:00'
// 59 seconds looks like this
format(1000 * 60 - 1) // '0:59'
// 60 minutes is an hour
format(1000 * 60 * 60) // '1:00:00'
// 59 minutes and 59 seconds looks like this
format(1000 * 60 * 60 - 1) // '59:59'
// 24 hours is a day
format(1000 * 60 * 60 * 24) // '1:00:00:00'
// 23 hours, 59 minutes, and 59 seconds looks like this
format(1000 * 60 * 60 * 24 - 1) // '23:59:59'
// 365 days looks like this (not bothering with years)
format(1000 * 60 * 60 * 24 * 365) // '365:00:00:00'
// anything under a second is rounded down to zero
format(-999) // '0:00'
// 1000 milliseconds is a second
format(-1000) // '-0:01'
// 365 days looks like this (not bothering with years)
format(-1000 * 60 * 60 * 24 * 365) // '-365:00:00:00'
// with `leading` option, formatting looks like this
format(1000 * 60, { leading: true }) // '01:00'
format(1000 * 60 - 1, { leading: true }) // '00:59'
format(1000 * 60 * 60, { leading: true }) // '01:00:00'
Contributions welcome! Please read the contributing guidelines first.
2.0.0 - 2022-03-16
FAQs
Convert a number in milliseconds to a standard duration string.
The npm package format-duration receives a total of 21,208 weekly downloads. As such, format-duration popularity was classified as popular.
We found that format-duration demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.