Format milliseconds into a human readable message by converting units
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
__tests__ ⭐️ Add largestOnly option, resolves #1 Oct 22, 2018
.editorconfig 🎉 First commit Oct 17, 2018
.eslintrc.js 🎉 First commit Oct 17, 2018
.gitignore 🎉 First commit Oct 17, 2018
.npmignore Add editorconfig & eslint conf to .npmignore Oct 18, 2018
README.md 📝 Fix typos in readme Oct 22, 2018
index.js ⭐️ Add largestOnly option, resolves #1 Oct 22, 2018
package-lock.json 1.1.3 Jan 8, 2019
package.json 1.1.3 Jan 8, 2019

README.md

Format Milliseconds

A utility function for converting milliseconds into a human readable message.

const { formatMilliseconds, parseMilliseconds } = require('format-ms')

console.log(formatMilliseconds(1000000))
// output: '16m 40s'

console.log(formatMilliseconds(-445500))
// output: '7m 25s 500ms ago'

console.log(formatMilliseconds(961000, { units: 'long' }))
// output: '16 minutes 1 second'

console.log(formatMilliseconds(-445500, { largestOnly: true }))
// output: '7m ago'

console.log(formatMilliseconds(445500, { ignore: [ 'millisecond' ] }))
// output: '7m 25s'

console.log(parseMilliseconds(987654321000))
// output: {
//   years: 31,
//   weeks: 21,
//   days: 0,
//   hours: 4,
//   minutes: 25,
//   seconds: 21,
//   milliseconds: 0 }