About
time-date-tools is a powerful Node.js module that allows you to easily manage time and date.
Features
Installation
npm install --save ms-time-tools
Examples
const tdt = require('time-date-tools');
Convert milliseconds to string time
The function formatTime()
converts time in milliseconds to a time in string with the format of your choice.
tdt.formatTime(time, options);
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 | ✅ | undefined | Format of string time returned. If not given, returns all the information about the time. |
lang | string | ✅ | en | Language of time unities ('en' or 'fr'). |
Some usage examples:
tdt.formatTime(654686145655, {});
tdt.formatTime(65364,
{ format: 'M:S.MS' }
);
tdt.formatTime(
449155098,
{
format: 'D DD, h:M:S.ms',
lang: 'en'
}
);
tdt.formatTime(31556927894,
{
format: '[y YY, mo MMOO,] d DD H:M:S.MS',
}
);
tdt.formatTime(31556927894,
{
format: 'y YY, mo MMOO, d DD H:M:S.MS',
}
);
Convert milliseconds to string date
The function formatDate()
converts date in milliseconds to a date in string with the format of your choice.
tdt.formatDate(date, options);
Here is the list of all the arguments available:
Parameter | Type | Optional | Default | Description |
---|
time | number | ❌ | | Date in milliseconds to convert into string. |
format | string | ✅ | undefined | Format of string date returned. If not given, returns all the information about the date. |
lang | string | ✅ | en | Language of date unities ('en' or 'fr'). |
Some usage examples:
tdt.formatDate(Date.now(), {});
tdt.formatDate(1654349360501,
{ format: 'M:S.MS' }
);
tdt.formatTime(Date.now(),
{
format: 'DD D/MO/Y at H:M:S.MS',
lang: 'en'
}
);
tdt.formatDate(0,
{
format: 'DD d-/MO/Y at H:M:S.MS',
}
);
tdt.formatTime(1623324464826,
{
format: 'DD d MMOO Y',
}
);
Convert string time to milliseconds time
The function parseTime()
converts time in string to a time in milliseconds.
tdt.parseTime(time, options);
Here is the list of all the arguments available:
Parameter | Type | Optional | Default | Description |
---|
time | number | ❌ | | Time in string to convert into milliseconds. |
msOff | boolean | ✅ | false | Returns the time in seconds instead of milliseconds. |
Some usage examples:
tdt.parseTime('2 days', {});
tdt.parseTime('5m 3s',
{ msOff: true }
);