aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/javascript/reference/global_objects/date/setutchours/index.html
blob: b99f7a9761b708edf9f8ee0cb7f1a0014295fb00 (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
90
91
92
---
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>{{Compat("javascript.builtins.Date.setUTCHours")}}</p>
</div>

<h2 id="相关链接">相关链接</h2>

<ul>
 <li>{{jsxref("Date.prototype.getUTCHours()")}}</li>
 <li>{{jsxref("Date.prototype.setHours()")}}</li>
</ul>