diff options
author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
---|---|---|
committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
commit | 33058f2b292b3a581333bdfb21b8f671898c5060 (patch) | |
tree | 51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/javascript/reference/global_objects/date/setmonth/index.html | |
parent | 8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff) | |
download | translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2 translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip |
initial commit
Diffstat (limited to 'files/zh-cn/web/javascript/reference/global_objects/date/setmonth/index.html')
-rw-r--r-- | files/zh-cn/web/javascript/reference/global_objects/date/setmonth/index.html | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/setmonth/index.html b/files/zh-cn/web/javascript/reference/global_objects/date/setmonth/index.html new file mode 100644 index 0000000000..010cf5f428 --- /dev/null +++ b/files/zh-cn/web/javascript/reference/global_objects/date/setmonth/index.html @@ -0,0 +1,86 @@ +--- +title: Date.prototype.setMonth() +slug: Web/JavaScript/Reference/Global_Objects/Date/setMonth +translation_of: Web/JavaScript/Reference/Global_Objects/Date/setMonth +--- +<div>{{JSRef("Global_Objects", "Date")}}</div> + +<p><code><strong>setMonth()</strong></code> 方法根据本地时间为一个设置年份的日期对象设置月份。</p> + +<div>{{EmbedInteractiveExample("pages/js/date-setmonth.html")}}</div> + +<h2 id="Syntax" name="Syntax">语法</h2> + +<pre class="syntaxbox"><var>dateObj</var>.setMonth(<em>monthValue</em>[, <em>dayValue</em>])</pre> + +<h3 id="Versions_prior_to_JavaScript_1.3" name="Versions_prior_to_JavaScript_1.3">JavaScript 1.3版本之前</h3> + +<pre class="syntaxbox"><var>dateObj</var>.setMonth(<em>monthValue</em>)</pre> + +<h3 id="Parameter" name="Parameter">参数</h3> + +<dl> + <dt><code>monthValue</code></dt> + <dd>介于 0 到 11 之间的整数(表示一月到十二月)。</dd> +</dl> + +<dl> + <dt><code>dayValue</code></dt> + <dd>从 1 到 31 之间的整数,表示月份中的第几天。0为上个月最后一天</dd> + <dt>返回值!</dt> + <dd>基于 1 January 1970 00:00:00 UTC 开始计算的毫秒数</dd> +</dl> + +<h2 id="Description" name="Description">描述</h2> + +<p>如果不指定 <code>dayValue</code> 参数,就会使用 {{jsxref("Date.getDate", "getDate")}} 方法的返回值。</p> + +<p>如果有一个指定的参数超出了合理范围,<code>setMonth</code> 会相应地更新日期对象中的日期信息。<font face="Courier New, Andale Mono, monospace">例如,为</font> <code>monthValue</code> 指定 15,则年份会加 1,月份将会使用 3。</p> + +<h2 id="Examples" name="Examples">例子</h2> + +<h3 id="Example_Using_setMonth" name="Example:_Using_setMonth">例子:使用<code>setMonth方法</code></h3> + +<pre class="brush: js">var theBigDay = new Date(); +theBigDay.setMonth(6); +</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>ECMAScript 1st Edition. Implemented in JavaScript 1.0</td> + <td>Standard</td> + <td>Initial definition.</td> + </tr> + <tr> + <td>{{SpecName('ES5.1', '#sec-15.9.5.38', 'Date.prototype.setMonth')}}</td> + <td>{{Spec2('ES5.1')}}</td> + <td></td> + </tr> + <tr> + <td>{{SpecName('ES6', '#sec-date.prototype.setmonth', 'Date.prototype.setMonth')}}</td> + <td>{{Spec2('ES6')}}</td> + <td></td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + +<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.setMonth")}}</p> + +<h2 id="See_Also" name="See_Also">相关链接</h2> + +<ul> + <li>{{jsxref("Date.prototype.getMonth()")}}</li> + <li>{{jsxref("Date.prototype.setUTCMonth()")}}</li> +</ul> |