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

149
Visualizações
Wrong Date displayed

I have the following in an html file to display today's Date.

<p id="todays-date">
   <script>
      var currentDate = new Date();
      var day = currentDate.getDay();
      var month = currentDate.getMonth();
      var year = currentDate.getFullYear();
      var fullDate = day + "/" + month + "/" + year;
      document.write(fullDate);
   </script>
</p>

As for today being the 23rd of September 2021 23/9/2021 in Australia the result I am getting is 4/8/2021.

Any help would be appreciated.

MiltonT.

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

getDay returns the current weekday and getMonth returns the current month, starting from 0

I would recommend you to take a look at the Date API docs

    var currentDate = new Date();
    var day = currentDate.getDate(); // Returns the day of the month (1–31) for the specified date according to local time.
    var month = currentDate.getMonth() + 1; // Returns the month (0–11) in the specified date according to local time.
    var year = currentDate.getFullYear();
    var fullDate = day + "/" + month + "/" + year;
    
    document.write(fullDate);

about 4 years ago · Juan Pablo Isaza Relatório

0

  • getDay gives you the day of the week, not the date. use getDate instead.
  • getMonth is zero-based. (january is 0, not 1). Add 1 to get the conventional one-based month.
about 4 years ago · Juan Pablo Isaza Relatório

0

Replace getDay with getDate, getDay returns the day of the week 0 represent Sunday and 6 represent Saturday. So 4 here in your question represent thursday

var currentDate = new Date();
var day = currentDate.getDate();
var month = currentDate.getMonth();
var year = currentDate.getFullYear();
var fullDate = day + "/" + month + "/" + year;
document.write(fullDate);

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