Skip to content

Instantly share code, notes, and snippets.

@mholtzhausen
Created November 26, 2019 12:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mholtzhausen/b8c9689c573c946adc8adcaa48669a3b to your computer and use it in GitHub Desktop.
Save mholtzhausen/b8c9689c573c946adc8adcaa48669a3b to your computer and use it in GitHub Desktop.
Milliseconds in Human friendly output
const humanMs = function(ms) {
let s = Math.floor(ms / 1000)
let m = Math.floor(s / 60)
let h = Math.floor(m / 60)
let d = Math.floor(h / 24)
ms = ms - s * 1000
s = s - m * 60
m = m - h * 60
h = h - d * 24
return `${d ? `${d}d, ` : ''}${h ? `${h}h ` : ''}${m ? `${m}m ` : ''}${
s > 0 ? `${s}` : ''
}${ms ? `.${ms}s` : `${s ? 's' : ''}`}`
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment