From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../global_objects/date/getmonth/index.html | 89 ++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 files/zh-cn/web/javascript/reference/global_objects/date/getmonth/index.html (limited to 'files/zh-cn/web/javascript/reference/global_objects/date/getmonth') diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/getmonth/index.html b/files/zh-cn/web/javascript/reference/global_objects/date/getmonth/index.html new file mode 100644 index 0000000000..bf2d68f24d --- /dev/null +++ b/files/zh-cn/web/javascript/reference/global_objects/date/getmonth/index.html @@ -0,0 +1,89 @@ +--- +title: Date.prototype.getMonth() +slug: Web/JavaScript/Reference/Global_Objects/Date/getMonth +tags: + - Date + - JavaScript + - Prototype + - 原型 + - 参考 + - 方法 +translation_of: Web/JavaScript/Reference/Global_Objects/Date/getMonth +--- +
{{JSRef}}
+ +

根据本地时间,返回一个指定的日期对象的月份,为基于0的值(0表示一年中的第一月)。

+ +
{{EmbedInteractiveExample("pages/js/date-getmonth.html")}}
+ + + +

语法

+ +
dateObj.getMonth()
+ +

参数

+ +

+ +

返回值

+ +

getMonth返回一个0 到 11的整数值: 0 代表一月份,1 代表二月份, 2 代表三月份,依次类推。

+ +

例子

+ +

使用 getMonth()

+ +

下面第二条语句,基于 {{jsxref("Date")}} 对象 Xmas95 的值,把11赋值给变量 month。

+ +
var Xmas95 = new Date('December 25, 1995 23:15:30');
+var month = Xmas95.getMonth();
+
+console.log(month); // 11
+ +

规范

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
规范版本规范状态注解
{{SpecName('ES1')}}{{Spec2('ES1')}}Initial definition.
{{SpecName('ES5.1', '#sec-15.9.5.12', 'Date.prototype.getMonth')}}{{Spec2('ES5.1')}} 
{{SpecName('ES6', '#sec-date.prototype.getmonth', 'Date.prototype.getMonth')}}{{Spec2('ES6')}} 
{{SpecName('ESDraft', '#sec-date.prototype.getmonth', 'Date.prototype.getMonth')}}{{Spec2('ESDraft')}} 
+ +

浏览器兼容性

+ +
+ + +

{{Compat("javascript.builtins.Date.getMonth")}}

+
+ +

相关链接

+ + -- cgit v1.2.3-54-g00ecf