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

181
Vistas
Get day works wrong in case new Date(year, month, day)

I'm trying to get day of week by :

const date = new Date('2021/12/06')
date.getDay()

and it works properly , but when I create date by using new Date(2021, 12, 6) , it show me wrong number - 4 . Why is it happens , or I don't understand some exception for this way of creating date object ?

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

0

this is because month should be the month index (0 - 11) not the month order (1-12):

new Date(2021, 11, 6).getDay()

and not

new Date(2021, 12, 6).getDay()

REF: Date() constructor: syntax

about 4 years ago · Juan Pablo Isaza Denunciar

0

When you create a date by 3 params you have to use a month INDEX. Starting by 0.

So December is actually 11, not 12.

If you use new Date(2021, 11, 6) you get the result you're looking for.

about 4 years ago · Juan Pablo Isaza Denunciar

0

getDay() gets the index of the week. Sunday, Monday, Tuesday, etc. (0, 1, 2,3,...)

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getDay

I believe what you're looking for is getDate() https://www.w3schools.com/js/js_date_methods.asp

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