aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/javascript/reference/global_objects/date/sethours/index.html
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
commit33058f2b292b3a581333bdfb21b8f671898c5060 (patch)
tree51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/javascript/reference/global_objects/date/sethours/index.html
parent8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff)
downloadtranslated-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/sethours/index.html')
-rw-r--r--files/zh-cn/web/javascript/reference/global_objects/date/sethours/index.html88
1 files changed, 88 insertions, 0 deletions
diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/sethours/index.html b/files/zh-cn/web/javascript/reference/global_objects/date/sethours/index.html
new file mode 100644
index 0000000000..f23dab9d13
--- /dev/null
+++ b/files/zh-cn/web/javascript/reference/global_objects/date/sethours/index.html
@@ -0,0 +1,88 @@
+---
+title: Date.prototype.setHours()
+slug: Web/JavaScript/Reference/Global_Objects/Date/setHours
+translation_of: Web/JavaScript/Reference/Global_Objects/Date/setHours
+---
+<div>{{JSRef("Global_Objects", "Date")}}</div>
+
+<p><code><strong>setHours()</strong></code> 方法根据本地时间为一个日期对象设置小时数,返回从1970-01-01 00:00:00 UTC 到更新后的 {{jsxref("Global_Objects/Date", "日期")}} 对象实例所表示时间的毫秒数。</p>
+
+<div>{{EmbedInteractiveExample("pages/js/date-sethours.html")}}</div>
+
+
+
+<h2 id="Syntax" name="Syntax">语法</h2>
+
+<pre class="syntaxbox">dateObj.setHours(<em>hoursValue</em>[, <em>minutesValue</em>[, <em>secondsValue</em><span style="line-height: normal;">[</span><span style="line-height: normal;">, </span><em>msValue</em><span style="line-height: normal;">]]])</span>
+</pre>
+
+<h3 id="Versions_prior_to_JavaScript_1.3" name="Versions_prior_to_JavaScript_1.3">JavaScript 1.3版本之前</h3>
+
+<pre class="syntaxbox"><code>dateObj.setHours(<em>hoursValue</em>) </code></pre>
+
+<h3 id="Parameters" name="Parameters">参数</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>secondsValue</code> 参数,则必须同时指定 <code>minutesValue </code>参数。</dd>
+ <dt><code>msValue</code></dt>
+ <dd>一个 0 到 999 的数字,表示微秒数,如果指定了 <code>msValue</code> 参数,则必须同时指定 <code>minutesValue</code> 和 <code>secondsValue</code> 参数。</dd>
+</dl>
+
+<h2 id="Description" name="Description">描述</h2>
+
+<p>如果不指定 <code>minutesValue</code>,<code>secondsValue</code> 和 <code>msValue</code> 参数,则会使用{{jsxref("Date.getMinutes", "getMinutes()")}},{{jsxref("Date.getSeconds", "getSeconds()")}} 和{{jsxref("Date.getMilliseconds", "getMilliseconds()")}} 方法的返回值。</p>
+
+<p>如果有一个参数超出了合理范围,<code>setHours</code> 会相应地更新日期对象中的日期信息。例如,如果为 <code>secondsValue</code> 指定了 100,则分钟会加 1,然后秒数使用 40。</p>
+
+<h2 id="Examples" name="Examples">例子</h2>
+
+<h3 id="Example:_Using_setHours" name="Example:_Using_setHours">例子:使用<code>setHours方法</code></h3>
+
+<pre class="brush:js">var theBigDay = new Date();
+theBigDay.setHours(7);
+</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.34', 'Date.prototype.setHours')}}</td>
+ <td>{{Spec2('ES5.1')}}</td>
+ <td> </td>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES6', '#sec-date.prototype.sethours', 'Date.prototype.setHours')}}</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.setHours")}}</p>
+
+<h2 id="See_Also" name="See_Also">相关链接</h2>
+
+<ul>
+ <li>{{jsxref("Date.prototype.getHours()")}}</li>
+ <li>{{jsxref("Date.prototype.setUTCHours()")}}</li>
+</ul>