diff options
Diffstat (limited to 'files/zh-cn/web/javascript/reference/global_objects/date/setutchours/index.html')
-rw-r--r-- | files/zh-cn/web/javascript/reference/global_objects/date/setutchours/index.html | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/setutchours/index.html b/files/zh-cn/web/javascript/reference/global_objects/date/setutchours/index.html new file mode 100644 index 0000000000..16d4989a4b --- /dev/null +++ b/files/zh-cn/web/javascript/reference/global_objects/date/setutchours/index.html @@ -0,0 +1,94 @@ +--- +title: Date.prototype.setUTCHours() +slug: Web/JavaScript/Reference/Global_Objects/Date/setUTCHours +translation_of: Web/JavaScript/Reference/Global_Objects/Date/setUTCHours +--- +<div>{{JSRef}}</div> + +<p>The <strong><code>setUTCHours()</code></strong> method sets the hour for a specified date according to universal time, and returns the number of milliseconds since 1 January 1970 00:00:00 UTC until the time represented by the updated {{jsxref("Date")}} instance.</p> + +<div>{{EmbedInteractiveExample("pages/js/date-setutchours.html")}}</div> + + + +<h2 id="Syntax">Syntax</h2> + +<pre class="syntaxbox"><code><var>dateObj</var>.setUTCHours(<var>hoursValue</var>[, <var>minutesValue</var>[, <var>secondsValue</var>[, <var>msValue</var>]]])</code></pre> + +<h3 id="参数"> 参数</h3> + +<dl> + <dt><code>hoursValue</code></dt> + <dd>表示小时的整数,取值0到23之间。</dd> + <dt><code>minutesValue</code></dt> + <dd>可选参数。表示分钟的整数,取值0到59之间。</dd> + <dt><code>secondsValue</code></dt> + <dd>可选参数。表示秒数的整数,取值0到59之间。如果指定了该参数,就要同时指定<code>minutesValue这个参数。</code></dd> + <dt><code>msValue</code></dt> + <dd>可选参数。表示毫秒的整数,取值0到999之间。如果指定了该参数,就要指定<code>minutesValue和secondsValue这两个参数。</code></dd> +</dl> + +<h3 id="返回值">返回值</h3> + +<p>返回从1970-01-01 00:00:00 UTC 到更新后的日期所表示时间的毫秒数。</p> + +<h2 id="描述">描述</h2> + +<p>If you do not specify the <code>minutesValue</code>, <code>secondsValue</code>, and <code>msValue</code> parameters, the values returned from the {{jsxref("Date.prototype.getUTCMinutes()", "getUTCMinutes()")}}, {{jsxref("Date.prototype.getUTCSeconds()", "getUTCSeconds()")}}, and {{jsxref("Date.prototype.getUTCMilliseconds()", "getUTCMilliseconds()")}} methods are used.</p> + +<p>If a parameter you specify is outside of the expected range, <code>setUTCHours()</code> attempts to update the date information in the {{jsxref("Date")}} object accordingly. For example, if you use 100 for <code>secondsValue</code>, the minutes will be incremented by 1 (<code>minutesValue + 1</code>), and 40 will be used for seconds.</p> + +<h2 id="例子">例子</h2> + +<h3 id="使用_setUTCHours()">使用 <code>setUTCHours()</code></h3> + +<pre class="brush: js">var theBigDay = new Date(); +theBigDay.setUTCHours(8); +</pre> + +<h2 id="规范">规范</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + <tr> + <td>{{SpecName('ES1')}}</td> + <td>{{Spec2('ES1')}}</td> + <td>Initial definition. Implemented in JavaScript 1.3.</td> + </tr> + <tr> + <td>{{SpecName('ES5.1', '#sec-15.9.5.35', 'Date.prototype.setUTCHours')}}</td> + <td>{{Spec2('ES5.1')}}</td> + <td> </td> + </tr> + <tr> + <td>{{SpecName('ES6', '#sec-date.prototype.setutchours', 'Date.prototype.setUTCHours')}}</td> + <td>{{Spec2('ES6')}}</td> + <td> </td> + </tr> + <tr> + <td>{{SpecName('ESDraft', '#sec-date.prototype.setutchours', 'Date.prototype.setUTCHours')}}</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.setUTCHours")}}</p> +</div> + +<h2 id="相关链接">相关链接</h2> + +<ul> + <li>{{jsxref("Date.prototype.getUTCHours()")}}</li> + <li>{{jsxref("Date.prototype.setHours()")}}</li> +</ul> |