Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why are we dividing the the difference of dates by 1000?

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Because when Date is converted to a number the value is in milliseconds
1 second === 1000 milliseconds

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading