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

274
Visualizações
How to add days to today? javascript

How to add days to today in day-month-year format? I tried this code but additionally get the time zone and month in the short word name. I want to receive, for example, August 12, 2023 here is the code:

Date.prototype.addDays = function(days) {
  var date = new Date(this.valueOf());
  date.setDate(date.getDate() + days);
  return date;
}

var date = new Date();

console.log(date.addDays(5));

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

0

To get the format: Month Day, Year, Simply use ECMAScript Internationalization API:

return date.toLocaleString('en-us',{month:'long', year:'numeric', day:'numeric'})
month:'long' //August
day:'numeric' //12
year:'numeric' //2023

Note: 'long' uses the full name of the month, 'short' for the short name,

about 4 years ago · Juan Pablo Isaza Relatório

0

Create an array of months

var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];

In the function Date.prototype.addDays, return the date string as

return months[date.getMonth()] + " " + date.getDate() + ", " + date.getFullYear();

Output:

July 15, 2022
about 4 years ago · Juan Pablo Isaza Relatório

0

You are adding 2 dates in a correct way, there is only problem in outputting the error. You can format date as follow based on this answer:

Date.prototype.addDays = function(days) {
  var date = new Date(this.valueOf());
  date.setDate(date.getDate() + days);
  
  // return formatted date
  var options = {year: 'numeric', month: 'long', day: 'numeric' };
  return date.toLocaleDateString("en-US", options);
}

var date = new Date();

console.log(date.addDays(5));

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