ms-time-tools is a powerful Node.js module that allows you to easily manage time.
npm install --save ms-time-tools
const mtt = require('ms-times-tools'); // Import the module
Here is the list of all the arguments available:
Parameter | Type | Optional | Default | Description |
---|---|---|---|---|
time | number | ❌ | Time in milliseconds to convert into string | |
format | string | ✅ | Y-MO-W-D-H-M-S-MS | Format and order of time returned |
lang | string | ✅ | en | Language of time unities |
long | boolean | ✅ | false | Returns the whole word (not abbreviations) |
separator | string | ✅ | , | Separators of time values |
suppressTag | boolean | ✅ | false | Returns time without unities |
valueNull | boolean | ✅ | false | Removes values equal to zero |
Some usage examples:
mtt.stringifyTime(61000); // 1m, 1s
mtt.stringifyTime(
617780000,
{
format: 'Y-MO-W-D-H-M-S-MS',
lang: 'en',
long: true
}
); // 1 week, 3 hours, 36 minutes, 20 seconds
mtt.stringifyTime(
5100300,
{
valueNull: true,
separator: '/'
}
); // 0y/0mo/0w/0d/1h/25m/0s/3ms
mtt.stringifyTime(
35071,
{ suppressTag: true }
); // 35, 71
Here is the list of all the arguments available:
Parameter | Type | Optional | Default | Description |
---|---|---|---|---|
time | string | ❌ | Time in string to convert into milliseconds | |
msOff | boolean | ✅ | false | Returns time in seconds instead of milliseconds |
Some usage examples:
mtt.parseTime('1 minute 1 second'); // 61000
mtt.parseTime(
'2h 5m',
{ msOff: true }
); // 7500
mtt.parseTime('1 month 2d 4hours'); // 187260000
mtt.stringifyTime(
35071,
{ suppressTag: true }
); // 35, 71
Here is the list of all the arguments available:
Parameter | Type | Optional | Default | Description |
---|---|---|---|---|
time | string | ❌ | Time to format | |
format | string | ✅ | y YYYY, mo MMMM, d DD H:M:S.MS | Format and order of time returned, check here for more information |
lang | string | ✅ | en | Language of time unities |
long | boolean | ✅ | false | Returns the whole word (not abbreviations) |
suppressTag | boolean | ✅ | false | Returns time without unities |
valueNull | boolean | ✅ | false | Removes values equal to zero |
Some usage examples:
mtt.formatTime(654686145655); // 20 years, 8 months, 29 days 01:00:25.655
mtt.formatTime(
65364,
{ format: 'M:S.MS' }
); // 01:05.364
mtt.formatTime(
449155098,
{ format: 'D DD, h:M:S.ms' }
); // 05 days, 4:45:55.98