Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
time-convert
Advanced tools
🕓 Convert durations to other time unit(s).
npm install time-convert
const { ms, s, m, h, d } = require('time-convert')
/* verbose equivalent */
const { milliseconds, seconds, minutes, hours, days } = require('time-convert')
/* convert milliseconds to hours, minutes and seconds */
ms.to(h,m,s)(12345678) // [4, 2, 47]
/* convert milliseconds to minutes and seconds */
ms.to(m,s)(12345678) // [242, 47]
/* get milliseconds from 12 hours, 23 minutes, 45 seconds*/
ms.from(h,m,s)(12, 23, 45) // 44625000
/* get hours from 123 minutes and 12 seconds */
h.from(m,s)(123, 12) // 2.0533333333333332
/* ⚠️ precision is lost */
ms.to(s)(1234) // [1] , not [1.234]
The only restriction is that units must be in descending order of magnitude – avoid calling ms.to(m, h, s)
.
time-convert
performs the convertion with the units you specify, but is agnostic as to what you want to do with the converted units.
It is encouraged that you create your own wrapper functions for you specific use-case.
For instance, to convert milliseconds to a hh:mm:ss
format, you can write the following:
const msToHms = ms => (
ms.to(h,m,s)(ms)
.map(n => n < 10? '0'+n : n.toString()) // zero-pad
.join(':')
)
msToHms(12345678) // '04:02:47'
Contributions welcome.
Possible additions:
npm run test
FAQs
convert miliseconds to any format
We found that time-convert demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.