JavaScript getMonth Function

JavaScript getMonth function is one of the Date Function, which returns the month number of a given date. This getMonth function returns Month number starting at 0 (January) and ends at 11 (December).

JavaScript getMonth Function Example

We are using the JavaScript get Month to return the month number (starts at 0 and ends at 11) in the current date and time.

<!DOCTYPE html>
<html>
<head>
    <title> JavaScript Get Month Function </title>
</head>
<body>
    <h1> JavaScript getMonth Function Example </h1>
<script>
  var dt = Date();  
  document.write("Date and Time : " + dt);
  document.write("Month Number using getMonth(): " + dt.getMonth());
</script>
</body>
</html>
JavaScript getMonth Function 1

This JavaScript get Month example returns the Month Number from the custom date

<!DOCTYPE html>
<html>
<head>
    <title> JavaScript Get Month Function </title>
</head>
<body>
    <h1> JavaScript getMonth Function Example </h1>
<script>
  var dt = Date("January 12, 2016 10:09:34");
  document.write("Date and Time : " + dt);
  document.write("Month Number using getMonth(): " + dt.getMonth());
</script>
</body>
</html>

getMonth Function Example 2

JavaScript getMonth Function Example

Date and Time: Tue Jan 12 2016 10:09:34 GMT+0530 (Indian Standard Time)
Month Number using getMonth(): 0

In this JavaScript get Month example, we extract the month from the custom year (I mean, without month or day).

<!DOCTYPE html>
<html>
<head>
    <title> JavaScript Get Month Function </title>
</head>
<body>
    <h1> JavaScript getMonth Function Example </h1>
<script>
  var dt = Date("2016 10:09:34");
  document.write("Date and Time : " + dt);
  document.write("Month Number using getMonth(): " + dt.getMonth());
</script>
</body>
</html>
JavaScript getMonth Function Example

Date and Time: Fri Jan 01 2016 10:09:34 GMT+0530 (Indian Standard Time)
Month Number using getMonth(): 0