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

134
Vistas
creating javascript Date object is not working properly

what is the problem and how to fix this ?

> new Date(2022,5,31)
< Fri Jul 01 2022 00:00:00 GMT+0430 (Iran Daylight Time)
> new Date("2022-5-31")
< Tue May 31 2022 00:00:00 GMT+0430 (Iran Daylight Time)

creating Date(2022,5,31) object

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Month is 0 indexed, i.e. 0 represents January. When you pass in a string with explicit date formatting like "2022-5-31" the month is not 0 indexed.

> new Date(2022,5,31)
                ^
              June
                   ^ 
                   31 -> 01 of the next month (Jul)
< Fri Jul 01 2022 00:00:00 GMT+0430 (Iran Daylight Time)

> new Date("2022-5-31")
                 ^
                May
                    ^
                   31 valid day
< Tue May 31 2022 00:00:00 GMT+0430 (Iran Daylight Time)

This becomes explicit when you try putting days of 35, for example:

> console.log(new Date(2022, 05, 35));
< Tue Jul 05 2022 00:00:00 GMT+0100 (British Summer Time)
about 4 years ago · Juan Pablo Isaza Denunciar

0

In the first example, January is 0 while in the second example, January is 1.

June only has 30 days so the extra 31st rolls over into July.

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