Now you can listen to this article with the Online Text Reader

JavaScript getMonth Method

The getMonth method returns the month of the point in time stored in a Date object. The value returned by this method is an integer number from 0 to 11, zero being January and eleven being December.



With myDate being an object based on the Date object.


The following code uses the getMonth method to return the month of the current date:

<script type="text/javascript">

function getMonthName(monthNumber)
  var monthNames = new Array("January", "February", "March", "April", "May", "June", "July","August","September", "October", "November", "December");
  return monthNames[monthNumber];

var currentDate = new Date();
var monthNumber = currentDate.getMonth();
var nameOfTheMonth = getMonthName(monthNumber);

document.write("The number of the current month is " + monthNumber + ", which means it is " + nameOfTheMonth + ".");


Technical Details

The getMonth method belongs to the Date object, it is available since the version 1.0 of JavaScript, and it is supported in all major browsers.

JavaScript Manual >> Date Object >> getMonth Method

© Copyright 2010-2018 ROM Cartridge

Books to Read and Listen to Online