Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

101
Views
moment.IsSame devolviendo un resultado incorrecto

Estoy usando el moment isSame que devuelve falso para dos fechas que son iguales,

 moment(new Date('2070-07-27T21:59:59.999Z')).isSame(moment(new Date('2070-07-27T23:00:58.000Z')), 'day');

Lo anterior devuelve falso aunque el mismo día, cualquier ayuda es apreciada

¿Qué método alternativo y preciso se puede usar si esto no funciona?

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

No tengo experiencia con el momento, pero

 const d1 = new Date('2070-07-27T21:59:59.999Z'); const d2 = new Date('2070-07-27T23:00:58.000Z'); console.log(d1.getDay()); // sunday console.log(d2.getDay()); // monday

Por lo tanto, no es un problema de momento.

Edito: Posible solución. Utilice la misma zona horaria para ambas fechas.

 console.log(d1.getUTCDay() === d2.getUTCDay()); // true (same weekday)

o

 console.log( (d1.getUTCDate() === d2.getUTCDate()) && (d1.getUTCMonth() === d2.getUTCMonth()) && (d1.getUTCFullYear() === d2.getUTCFullYear()) ); // true (same date)

o

 const moment = require('moment'); const d1 = new Date('2070-07-27T21:59:59.999Z'); const d2 = new Date('2070-07-27T23:00:58.000Z'); const isSame = moment(d1).isSame(moment(d2), 'day'); console.log(isSame); // false const isSameFixed = moment(d1).utc().isSame(moment(d2).utc(), 'day'); console.log(isSameFixed); // true
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!