English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

JavaScript getMonth() 方法

 JavaScript Date Object

getMonth() 根据本地时间返回指定日期对象的月份(0-11)

getMonth()返回的值是与一年中的月份对应的整数:0表示一月,1表示二月,依此类推。

对于星期几,请参见getDay()方法。

有关每月的某天,请参见getDate()方法。

Syntax:

date.getMonth()
var d = new Date();
d.getMonth();
Test and see‹/›

Browser Compatibility

All browsers fully support the getMonth() method:

Method
getMonth()isisisisis

Technical Details

Return Value:0 to11integer between the two, representing the month of the year
JavaScript Version:ECMAScript 1

More Examples

Return the month of the year from a specific date and time:

var d = new Date('August 20, 1999 23:15:30');
d.getMonth();
Test and see‹/›

The month variable stores the name of the month:

var arr = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
var d = new Date();
var month = arr[d.getMonth()];
Test and see‹/›

 JavaScript Date Object