Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

133
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda