Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

99
Visualizações
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).

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

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

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda