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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
---
title: Date.UTC()
slug: Web/JavaScript/Reference/Global_Objects/Date/UTC
tags:
- Date
- JavaScript
- 參考
- 方法
translation_of: Web/JavaScript/Reference/Global_Objects/Date/UTC
---
<div>{{JSRef}}</div>
<p><strong><code>Date.UTC()</code></strong> 方法接受與建構子相同長度的參數,將參數視為通用時間(UTC)來計算回傳由 1970-01-01 00:00:00 UTC 所經過的毫秒數。</p>
<h2 id="格式">格式</h2>
<pre class="syntaxbox"><code>Date.UTC(<var>year</var>, <var>month</var>[, <var>day</var>[, <var>hour</var>[, <var>minute</var>[, <var>second</var>[, <var>millisecond</var>]]]]])</code></pre>
<h3 id="參數">參數</h3>
<dl>
<dt><code>year</code></dt>
<dd>1900 年後的年份。</dd>
<dt><code>month</code></dt>
<dd>月份,介於 0 到 11 之間。</dd>
<dt><code>day</code></dt>
<dd>選用。月份中的日期,介於 1 到 31 之間。</dd>
<dt><code>hour</code></dt>
<dd>選用。小時,介於 0 到 23 之間。</dd>
<dt><code>minute</code></dt>
<dd>選用。分鐘數,介於 0 到 59 之間。</dd>
<dt><code>second</code></dt>
<dd>選用。秒數,介於 0 到 59 之間。</dd>
<dt><code>millisecond</code></dt>
<dd>選用。毫秒數 0 到 999 之間。</dd>
</dl>
<h3 id="回傳值">回傳值</h3>
<p>得到傳入這個 {{jsxref("Date")}} 方法的參數所代表時間,與 1970-01-01 00:00:00 UTC 相差的毫秒數。</p>
<h2 id="描述">描述</h2>
<p><code>UTC()</code> 取得以逗號分隔的時間參數,回傳 1970-01-01 00:00:00 UTC 與該時間相差的毫秒數。</p>
<p>你應該指定完成的年份資料,例如: 1998。如果一個 0 到 99 的年份被指定,這個方法會將它轉換為 20 世紀的年份(變為 19xx 年),例如你傳入 95 ,則會被當作 1995 年被指定。</p>
<p>這個 <code>UTC()</code> 方法與 {{jsxref("Date")}} 建構子有兩個地方不同。</p>
<ul>
<li><code>Date.UTC()</code> 使用 UTC 時區而不是當地時區。</li>
<li><code>Date.UTC()</code> 回傳一個數值而不是 {{jsxref("Date")}} 物件。</li>
</ul>
<p>當你指定參數超出預期的範圍, UTC( ) 方法會去調整其它的參數使之成立。比如如果你指定月份為 15 ,年份將被加 1 ,以 3 作為傳入的月份。</p>
<p>因為 UTC( ) 是 {{jsxref("Date")}} 的一個靜態方法,只能使用 <code>Date.UTC() 的方式呼叫,而不能由建立出來的 </code>{{jsxref("Date")}} 物件去執行它。</p>
<h2 id="範例">範例</h2>
<h3 id="使用_Date.UTC()">使用 <code>Date.UTC()</code></h3>
<p>以下利用它來將指定的時間以 UTC 而非本地時間的方式來建立 {{jsxref("Date")}} 物件:</p>
<pre class="brush:js">var utcDate = new Date(Date.UTC(96, 11, 1, 0, 0, 0));
</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>{{SpecName('ESDraft', '#sec-date.utc', 'Date.UTC')}}</td>
<td>{{Spec2('ESDraft')}}</td>
<td> </td>
</tr>
<tr>
<td>{{SpecName('ES6', '#sec-date.utc', 'Date.UTC')}}</td>
<td>{{Spec2('ES6')}}</td>
<td> </td>
</tr>
<tr>
<td>{{SpecName('ES5.1', '#sec-15.9.4.3', 'Date.UTC')}}</td>
<td>{{Spec2('ES5.1')}}</td>
<td> </td>
</tr>
<tr>
<td>{{SpecName('ES1')}}</td>
<td>{{Spec2('ES1')}}</td>
<td>初始定義。<br>
實作在 JavaScript 1.0.</td>
</tr>
</tbody>
</table>
<h2 id="瀏覽器相容性">瀏覽器相容性</h2>
<div>{{CompatibilityTable}}</div>
<div id="compat-desktop">
<table class="compat-table">
<tbody>
<tr>
<th>平台</th>
<th>Chrome</th>
<th>Firefox (Gecko)</th>
<th>Internet Explorer</th>
<th>Opera</th>
<th>Safari</th>
</tr>
<tr>
<td>基本支援</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatVersionUnknown}}</td>
</tr>
</tbody>
</table>
</div>
<div id="compat-mobile">
<table class="compat-table">
<tbody>
<tr>
<th>平台</th>
<th>Android</th>
<th>Chrome for Android</th>
<th>Firefox Mobile (Gecko)</th>
<th>IE Mobile</th>
<th>Opera Mobile</th>
<th>Safari Mobile</th>
</tr>
<tr>
<td>基本支援</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatUnknown}}</td>
</tr>
</tbody>
</table>
</div>
<h2 id="相關資源">相關資源</h2>
<ul>
<li>{{jsxref("Date.parse()")}}</li>
</ul>
|