Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
time-date-tools
Advanced tools
time-date-tools is a powerful Node.js module that allows you to easily manage time and date.
time-date-tools is a powerful Node.js module that allows you to easily manage time and date.
npm install --save time-date-tools
const tdt = require('time-date-tools'); // Import the module
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'). |
You can enclose certain parts of your format with brackets []
, the values contained in these brackets will be displayed even if they are null.
Some usage examples:
tdt.formatTime(654686145655, {});
/*
{
y: 20, mo: 8, d: 29, h: 1, m: 0, s: 25, ms: 655,
YY: 'years', MMOO: 'months', DD: 'days', HH: 'hour', MM: 'minute', SS: seconds', MMSS: 'milliseconds',
Y: '20', MO: '08', D: '29', H: '01', M: '00', S: '25', MS: '655',
yy: 'y', mmoo: 'mo', dd: 'd', hh: 'h', mm: 'm', ss: 's', mmss: 'ms'
}
*/
tdt.formatTime(65364,
{ format: 'M:S.MS' }
); // 01:05.364
tdt.formatTime(
449155098,
{
format: 'D DD, h:M:S.ms',
lang: 'en'
}
); // 05 days, 4:45:55.98
tdt.formatTime(31556927894,
{
format: '[y YY, mo MMOO,] d DD H:M:S.MS',
}
); // 1 year, 0 month, 01.894
tdt.formatTime(31556927894,
{
format: 'y YY, mo MMOO, d DD H:M:S.MS',
}
); // 1 year, 01.894
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(), {});
/*
{
date: 2022-06-04T13:28:31.790Z,
milliseconds: 790,
millisecondsFull: '790',
seconds: 31,
secondsFull: '31',
minutes: 28,
minutesFull: '28',
hours: 15,
hoursFull: '15',
days: 'sunday',
daysNumber: 4,
daysNumberIndice: '4',
daysFullNumber: '04',
daysFullNumberIndice: '04',
months: 'june',
monthsNumber: 6,
monthsFullNumber: '06',
years: '22',
yearsFull: 2022
}
*/
tdt.formatDate(1654349360501,
{ format: 'M:S.MS' }
); // 29:44.883
tdt.formatTime(Date.now(),
{
format: 'DD D/MO/Y at H:M:S.MS',
lang: 'en'
}
); // sunday 04/06/2022 at 15:31:00.760
tdt.formatDate(0,
{
format: 'DD d-/MO/Y at H:M:S.MS',
}
); // friday 1nd/01/1970 at 01:00:00.000
tdt.formatTime(1623324464826,
{
format: 'DD d MMOO Y',
}
); // friday 10 june 2021
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', {}); // 172800000
tdt.parseTime('5m 3s',
{ msOff: true }
); // 303
Availables tokens for the date format.
Token | Description | Output |
---|---|---|
Y | four-digit year | 2022 |
y | two-digit year | 22 |
MMOO | month name | January |
MO | two-digit month | 01 |
mo | month | 1 |
DD | day name | Monday |
D | two-digit day | 01 |
D- | two-digit day with indice | 01st |
d | day | 1 |
d- | one-digit day with indice | 1st |
H | two-digit hour | 09, 14 |
h | hour | 9, 14 |
M | two-digit minute | 05, 34 |
m | minute | 5, 34 |
S | two-digit second | 02, 58 |
s | second | 2, 58 |
MS | three-digit millisecond | 009, 158 |
ms | millisecond | 9, 158 |
Availables tokens for the time format.
Token | Description | Output |
---|---|---|
YY | year unity (long) | year, years |
yy | year unity (short) | y |
Y | four-digit year | 2022 |
y | two-digit year | 22 |
MMOO | month unity (long) | month, months |
mmoo | month unity (short) | m |
MO | two-digit month | 01 |
mo | month | 1 |
DD | day unity (long) | day, days |
dd | day unity (short) | d |
D | two-digit day | 01 |
d | day | 1 |
HH | hour unity (long) | hour, hours |
hh | hour unity (short) | h |
H | two-digit hour | 09, 14 |
h | hour | 9, 14 |
MM | minute unity (long) | minute, minutes |
mm | minute unity (short) | m |
M | two-digit minute | 05, 34 |
m | minute | 5, 34 |
SS | second unity (long) | seconds, second |
ss | second unity (short) | s |
S | two-digit second | 02, 58 |
s | second | 2, 58 |
MMSS | millisecond unity (long) | millisecond, milliseconds |
mmss | millisecond unity (short) | ms |
MS | three-digit millisecond | 009, 158 |
ms | millisecond | 9, 158 |
FAQs
`time-date-tools` is a powerful Node.js module that allows you to **easily manage time** and **date**. You can configure a lot of features to not have date and time issues anymore. If you have any question, you can join our community on [**Discord*
The npm package time-date-tools receives a total of 15 weekly downloads. As such, time-date-tools popularity was classified as not popular.
We found that time-date-tools 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.