var newYear = "1 jan 2022";
function countDates() {
var newYearDate = new Date(newYear);
var currentDate = new Date();
const days = Math.floor((newYearDate - currentDate) / (1000*60 * 60 * 24));
const hours = Math.floor((newYearDate - currentDate) / (1000 * 60 * 60));
const minutes = Math.floor((newYearDate - currentDate) / (1000 * 60));
const seconds = Math.floor((newYearDate - currentDate) / 1000);
console.log(days, hours, minutes,seconds);
}
countDates();
In this code I have substracted the initialized(NewYearDate) date with the current date and tried to get days, hours, minutes out of it, I got the logic on the internet but can’t understand why it is divided by 1000 for all the variables (days, hours, minutes).
>Solution :
Because when Date is converted to a number the value is in milliseconds
1 second === 1000 milliseconds