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

146
Vistas
Get next month from current date in html using javascript

I want to display a p tag with the next month, for example now is December But the p tag should be display January, If we in Jan the p tag should be display Febrary. What I have until now is this.

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

const d = new Date();
let name = month[d.getMonth()];
document.getElementById("currentmonth").innerHTML = name;
<!DOCTYPE html>
<html>
<body>
<p id="currentmonth"></p>
<p id="nextmonth"></p>

</body>
</html>

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

0

Simply take a variable and add one to the getMonth() value and if it is greater than 11 then change it to 0.

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

const d = new Date();
let name = month[d.getMonth()];
var x = d.getMonth()+1;
if(x>11)
  x=0
  
document.getElementById("currentmonth").innerHTML = name;
document.getElementById("nextmonth").innerHTML = month[x];
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
<p id="currentmonth"></p>
<p id="nextmonth"></p>

</body>
</html>

about 4 years ago · Juan Pablo Isaza Denunciar

0

You have to use setMonth to set the next month on the d variable.

d.setMonth(Month + 1) 

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

    let Month = 11 
   const d = new Date();
d.setMonth(Month + 1)
let name = month[d.getMonth()];
document.getElementById("currentmonth").innerHTML = name;
<!DOCTYPE html>
<html>
<body>
<p id="currentmonth"></p>
<p id="nextmonth"></p>

</body>
</html>

about 4 years ago · Juan Pablo Isaza Denunciar

0

If the order of the months is according to the real month indexes, you can do it as follows.

and i guess you forgot set value nextMonth

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

const d = new Date();
let name = month[d.getMonth()];
let next = month[(new Date().getMonth()+1)%12];
document.getElementById("currentmonth").innerHTML = `Current: ${name}`;
document.getElementById("nextmonth").innerHTML = `Next: ${next}`;
<!DOCTYPE html>
<html>
<body>
<p id="currentmonth"></p>
<p id="nextmonth"></p>

</body>
</html>

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