Answer the question
In order to leave comments, you need to log in
Who faced the problem in platformio-ide-terminal?
an empty terminal appears, with a blinking cursor, I can not configure it correctly. The version is the latest, it is impossible to add text to the terminal.
Answer the question
In order to leave comments, you need to log in
// why this zero?
To get not 3 minutes, but 03, someone "smart" came up with the idea of adding a zero at the beginning, and then taking the last two characters.
Could it be replaced with x<10 ? '0' + x : x
// Like 3 first and 3 last elements of array d. What for?
well, like year.month.day hh:mm:ss
But better throw this garbage away and learn how to use Intl.DateTimeFormat
Learning simple debugging. We display the places of interest in the console:
function formatDate(date) {
/* код без изменений */
let d = date;
const dWithoutZeros = [
d.getDate(),
(d.getMonth() + 1),
d.getFullYear(),
d.getHours(),
d.getMinutes()
];
console.log('d[]: ', dWithoutZeros);
d = [
'0' + d.getDate(),
'0' + (d.getMonth() + 1),
'' + d.getFullYear(),
'0' + d.getHours(),
'0' + d.getMinutes()
];
console.log('d[] with zeros: ', d);
d = d.map(component => component.slice(-2));
console.log('d[] sliced: ', d);
const a = d.slice(0, 3).join('.');
console.log('part a: ', a);
const b = d.slice(3).join(':');
console.log('part b: ', b);
const result = a + ' ' + b;
console.log('result: ', result);
return result;
}
/* код без изменений */
console.log('case 1: ', new Date - 1);
console.log('case 2: ', new Date(new Date - 1));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question