How to use getMonth in JavaScript
In this article, I will explain use of getMonth() Method in JavaScript.
JavaScript date getMonth() method
-
getMonth() method of date object returns the month in the specified date according to local time.
-
In getMonth() method, The returned value is an integer number between 0 and 11. just like January is 0, February is 1, and so on.
Syntax
Example
In the following example show to getMonth() method returns current month.
<!DOCTYPE html>
<html>
<body>
<h3 style="color:Blue">JavaScript getMonth() Method Example</h3>
<p id="demo">Click For display Current month</p>
<button onclick="myFunction()">Try it</button>
<script type="text/javascript">
function myFunction() {
var month = new Array();
month[0] = "January";
month[1] = "February";
month[2] = "March";
month[3] = "April";
month[4] = "May";
month[5] = "June";
month[6] = "July";
month[7] = "August";
month[8] = "September";
month[9] = "October";
month[10] = "November";
month[11] = "December";
var d = new Date();
var x = document.getElementById("demo");
//x.innerHTML = ;
document.write("Current Month is: " + month[d.getMonth()]);
}
</script>
</body>
</html>
|
Output1
Output2
You may also want to read these related articles here
Ask Your Question
Got a programming related question? You may want to post your question here
Programming Answers here