aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/javascript/reference/global_objects/date/getmonth/index.html
blob: bf2d68f24d1a1709c419b78f3f6180b779355505 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
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
---
<div>{{JSRef}}</div>

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

<div>{{EmbedInteractiveExample("pages/js/date-getmonth.html")}}</div>



<h2 id="Syntax" name="Syntax">语法</h2>

<pre class="syntaxbox  language-html">dateObj.getMonth()</pre>

<h3 id="Parameters" name="Parameters">参数</h3>

<p></p>

<h3 id="Description" name="Description">返回值</h3>

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

<h2 id="Examples" name="Examples">例子</h2>

<h3 id="Example:_Using_getMonth" name="Example:_Using_getMonth">使用 <code>getMonth()</code></h3>

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

<pre class="brush:js  language-js">var Xmas95 = new Date('December 25, 1995 23:15:30');
var month = Xmas95.getMonth();

console.log(month); // 11</pre>

<h2 id="规范">规范</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">规范版本</th>
   <th scope="col">规范状态</th>
   <th scope="col">注解</th>
  </tr>
  <tr>
   <td>{{SpecName('ES1')}}</td>
   <td>{{Spec2('ES1')}}</td>
   <td>Initial definition.</td>
  </tr>
  <tr>
   <td>{{SpecName('ES5.1', '#sec-15.9.5.12', 'Date.prototype.getMonth')}}</td>
   <td>{{Spec2('ES5.1')}}</td>
   <td> </td>
  </tr>
  <tr>
   <td>{{SpecName('ES6', '#sec-date.prototype.getmonth', 'Date.prototype.getMonth')}}</td>
   <td>{{Spec2('ES6')}}</td>
   <td> </td>
  </tr>
  <tr>
   <td>{{SpecName('ESDraft', '#sec-date.prototype.getmonth', 'Date.prototype.getMonth')}}</td>
   <td>{{Spec2('ESDraft')}}</td>
   <td> </td>
  </tr>
 </tbody>
</table>

<h2 id="浏览器兼容性">浏览器兼容性</h2>

<div>
<p class="hidden">The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> and send us a pull request.</p>

<p>{{Compat("javascript.builtins.Date.getMonth")}}</p>
</div>

<h2 id="See_Also" name="See_Also" style="margin-bottom: 20px; line-height: 30px;">相关链接</h2>

<ul>
 <li>{{jsxref("Date.prototype.getUTCMonth()")}}</li>
 <li>{{jsxref("Date.prototype.setMonth()")}}</li>
</ul>