22 lines
444 B
JavaScript
22 lines
444 B
JavaScript
|
|
function pad(value) {
|
||
|
|
return value < 10 ? `0${value}` : `${value}`;
|
||
|
|
}
|
||
|
|
|
||
|
|
function formatDate(date) {
|
||
|
|
const year = date.getFullYear();
|
||
|
|
const month = pad(date.getMonth() + 1);
|
||
|
|
const day = pad(date.getDate());
|
||
|
|
return `${year}-${month}-${day}`;
|
||
|
|
}
|
||
|
|
|
||
|
|
function formatTime(date) {
|
||
|
|
const hours = pad(date.getHours());
|
||
|
|
const minutes = pad(date.getMinutes());
|
||
|
|
return `${hours}:${minutes}`;
|
||
|
|
}
|
||
|
|
|
||
|
|
module.exports = {
|
||
|
|
formatDate,
|
||
|
|
formatTime
|
||
|
|
};
|