' Il getMonth()metodo restituisce il mese di una data come numero (0-11):
https://www.w3schools.com/js/tryit.asp?filename=tryjs_date_getmonth <!DOCTYPE html> <html> <body> <h2>JavaScript getMonth()</h2> <p>The getMonth() method returns the month of a date as a number from 0 to 11.</p> <p>To get the correct month, you must add 1:</p> <p id="demo"></p> <script> var d = new Date(); document.getElementById("demo").innerHTML = d.getMonth() + 1; </script> </body> </html> 'In JavaScript, il primo mese (gennaio) e' il mese numero 0, quindi dicembre restituisce il mese numero 11. 'E' possibile utilizzare una matrice di nomi e getMonth()restituire il mese come nome: 'Esempio 'var d = new Date(); 'var months = ["Gennaio","Febbraio","Marzo","Aprile","Maggio","Giugno","Luglio","Agosto","Seytembre","Ottobre","Novembre","Dicembre"]; 'document.getElementById("demo").innerHTML = months[d.getMonth()]; <!DOCTYPE html> <html> <body> <h2>JavaScript getMonth()</h2> <p>The getMonth() method returns the month as a number:</p> <p>You can use an array to display the name of the month:</p> <p id="demo"></p> <script> var d = new Date(); var months = ["Gennaio","Febbraio","Marzo","Aprile","Maggio","Giugno","Luglio","Agosto","Seytembre","Ottobre","Novembre","Dicembre"]; document.getElementById("demo").innerHTML = months[d.getMonth()]; </script> </body> </html> |