Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

154
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda