About
ms-time-tools is a powerful Node.js module that allows you to easily manage time.
Features
Installation
npm install --save ms-time-tools
Examples
const mtt = require('ms-times-tools');
Convert from milliseconds
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);
mtt.stringifyTime(
617780000,
{
format: 'Y-MO-W-D-H-M-S-MS',
lang: 'en',
long: true
}
);
mtt.stringifyTime(
5100300,
{
valueNull: true,
separator: '/'
}
);
mtt.stringifyTime(
35071,
{ suppressTag: true }
);
Convert from string
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');
mtt.parseTime(
'2h 5m',
{ msOff: true }
);
mtt.parseTime('1 month 2d 4hours');
mtt.stringifyTime(
35071,
{ suppressTag: true }
);
Format time
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);
mtt.formatTime(
65364,
{ format: 'M:S.MS' }
);
mtt.formatTime(
449155098,
{ format: 'D DD, h:M:S.ms' }
);