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

156
Visualizações
Dayjs and plain date objects give different difference

At this link of the Dayjs library you will read this:

const date1 = dayjs('2019-01-25')
const date2 = dayjs('2018-06-05')
date1.diff(date2) // 20214000000 default milliseconds

But if you type in the console, you'll get this:

new Date(2019,0,25) - new Date(2018,5,5)
// result: 20221200000

Why the difference?

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

0

const dayjs = require("dayjs")

const date1 = dayjs("2019-01-25")
const date2 = dayjs("2018-06-05")
console.log(date1.diff(date2)) // 20214000000

console.log(new Date(2019, 0, 25) - new Date(2018, 5, 5)) // 20214000000
console.log(new Date(2019, 0, 25).getTime() - new Date(2018, 5, 5).getTime()) // 20214000000

You can get the timestamp of Date with the .getTime() function, and in this case you are just doing 1548381600000 - 1528167600000. I'm not sure how did you get 20221200000 but this value is just wrong.

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