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

180
Visualizações
Get Current Date using JS

I'm trying to get the current date so I can use it at the ending of this link. My code is almost correct but can't figure out what is going wrong.

  • Correct Format Example: **http://zumdb-prod.itg.com/zum/AppServlet?action=aotool&jspURL=clusterTools/toolset.jsp&fegoaltype=RAW&eedbListName=ZUM_CMP_DNS_CMP_Clean&facility=DMOS5-CLUSTER&monthDate=01/09/2022

My results are almost correct but the code returns with the following date 01/0/2022 instead of 01/09/2022

Can someone help me figure out this small bug?

<script>
    const getDate = () => {
        let newDate = new Date();
        let year = newDate.getFullYear();
        let month = newDate.getMonth() + 1;
        let d = newDate.getDay();
        return month + '/' + d + '/' + year;
    }



    document.getElementById('Ao').src =
        'http://zumdb-prod.itg.com/zum/AppServlet?action=aotool&jspURL=clusterTools/toolset.jsp&fegoaltype=RAW&eedbListName=ZUM_CMP_DNS_CMP_Clean&facility=DMOS5-CLUSTER&monthDate='
        .concat(getDate());

    document.getElementById('MTD').src =
        'http://zumdb-prod.itg.com/zum/AppServlet?action=aotoolFe&jspURL=clusterTools/toolsetFe.jsp&fegoaltype=RAW&eedbListName=ZUM_DIFF_TEL_IPD_HTO&facility=DMOS5-CLUSTER&monthDate='
        .concat(getDate());
</script>
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You should be using getDate() and not getDay(). The latter returns the zero-based day of the week (starting Sunday). You want to get the date of the month.

In order to ensure you get double digits for the month and day, you need to convert those numbers to string first, and then use String.prototype.padStart.

const getDate = () => {
  const newDate = new Date();
  const year = newDate.getFullYear();
  const month = newDate.getMonth() + 1;
  const d = newDate.getDate();
  
  return `${month.toString().padStart(2, '0')}/${d.toString().padStart(2, '0')}/${year}`;
}

console.log(getDate());

about 4 years ago · Juan Pablo Isaza Relatório

0

Here are alternative methods for native date formatting using toLocaleString()

m/d/yyyy

const getDate = () => {
  const date = new Date();
  return date.toLocaleString().split(",")[0];
}

console.log(getDate());

mm/dd/yyyy

const getDate = () => {
  const date = new Date();
  return date.toLocaleString('en-US', {
    month: '2-digit',
    day: '2-digit',
    year: 'numeric'
  });
}

console.log(getDate());

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