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
New date function is not returning future date as expected

I need Date in IST format so here I am trying to pass the date into three formats, first format gives the correct result but I need the second and third format where the year is passed in the last two digits but if the digits are less then 50 it's giving correct result if it is more then 50 it's giving 1950 as year, in my code I need it to pass as two digits only.

Basically, I need the date format as dd-mm-yy or dd/mm/yy

console.log(new Date(
  `04/1/2050`
))// correct
console.log(new Date(
  `04/1/50`
))// false
  console.log(new Date(
    `04/1/40`
  ))// correct

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

0

Following are the rules from ECMA (https://262.ecma-international.org/11.0/#sec-date-constructor)

If 0 ≤ yi ≤ 99, let yr be 1900 + yi; otherwise, let yr be y.

So this

console.log(new Date(
    `04/1/40`
  ))

// 1940-03-31

I guess Browser's are taking liberty in this rule. And changed this rule to something like

If 0 ≤ yi ≤ 49, let yr be 2000 + yi

You can use same logic in your code too. But make sure it is implemented same way in every browser.

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