aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/javascript/reference/global_objects/date/settime/index.html
blob: 28e6aee649365965379c38e6454f954766a4d949 (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
---
title: Date.prototype.setTime()
slug: Web/JavaScript/Reference/Global_Objects/Date/setTime
translation_of: Web/JavaScript/Reference/Global_Objects/Date/setTime
---
<div>{{JSRef("Global_Objects", "Date")}}</div>

<p><code><strong>setTime()</strong></code> 方法以一个表示从1970-1-1 00:00:00 UTC计时的毫秒数为来为 <code>Date</code> 对象设置时间。</p>

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



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

<pre class="syntaxbox"><var>dateObj</var>.setTime(<em>timeValue</em>)</pre>

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

<dl>
 <dt><code>timeValue</code></dt>
 <dd>一个整数,表示从1970-1-1 00:00:00 UTC开始计时的毫秒数。</dd>
</dl>

<h3 id="Parameters">返回值</h3>
<p>UTC 1970年1月1日00:00:00与更新日期之间的毫秒数(实际上是自变量的值)。</p>

<h2 id="Description">描述</h2>

<p>使用 <code>setTime</code> 方法用来把一个日期时间赋值给另一个 <code>Date </code>对象。</p>

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

<h3 id="Example_Using_setTime">例子:使用<code>setTime</code></h3>

<pre>theBigDay = new Date("July 1, 1999");
sameAsBigDay = new Date();
sameAsBigDay.setTime(theBigDay.getTime());
</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.27', 'Date.prototype.setTime')}}</td>
   <td>{{Spec2('ES5.1')}}</td>
   <td></td>
  </tr>
  <tr>
   <td>{{SpecName('ES6', '#sec-date.prototype.settime', 'Date.prototype.setTime')}}</td>
   <td>{{Spec2('ES6')}}</td>
   <td></td>
  </tr>
 </tbody>
</table>

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

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

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

<ul>
 <li>{{jsxref("Date.prototype.getTime()")}}</li>
 <li>{{jsxref("Date.prototype.setUTCHours()")}}</li>
</ul>