Date getMonth() method with example in JavaScript

JavaScript Date getMonth() method: Here, we are going to learn about the getMonth() method of Date class with Example in JavaScript.
Submitted by IncludeHelp, on March 04, 2019

JavaScript Date getMonth() method

getMonth() method is a Date's class method and it is used to get the value of the month from the current date.

It accepts nothing as the parameter and returns a value between 0 to 11.

Note: Returned value is from 0 to 11, 0 for January, 1 for February, ..., 11 for December

Syntax:

    var dt = new Date();
    dt.getMonth();

Examples:

    Input:
    var dt = new Date();
    dt.getMonth();
    
    Output:
    2 (if current month is March)

JavaScript code to get the month value from the current date using getMonth() method

<html>
<head><title>JavaScipt Example</title></head>

<body>
<script>
	var dt = new Date(); //Date constructor 
	var month = dt.getMonth(); //getting month from the current date
	//printing month
	document.write("Current month is : " + month);
</script>
</body>
</html>

Output

Current month is : 2

JavaScript Date Object Methods »




Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.