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

<p><strong><code>setUTCDate()</code></strong> 方法就是根据全球时间设置特定date对象的日期。</p>

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



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

<pre class="syntaxbox"><code><var>dateObj</var>.setUTCDate(<var>dayValue</var>)</code></pre>

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

<dl>
 <dt><code>dayValue</code></dt>
 <dd>一个1-31的整形数字,用来指定日期。</dd>
</dl>

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

<p>如果你指定的参数超出了范围,setUTCDate()会尝试更新对应的{{jsxref("Global_Objects/Date", "Date")}} 中的日期信息。例如,如果你使用了40来作为参数,但是{{jsxref("Global_Objects/Date", "Date")}} 中存储的月份为6月,那么日期将被改写为10且月份被增到7月。</p>

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

<h3 id="Example:_Using_setUTCDate">使用Using <code>setUTCDate()</code></h3>

<pre class="brush: js">var theBigDay = new Date();
theBigDay.setUTCDate(20);
</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>ECMAScript 1st Edition.</td>
   <td>Standard</td>
   <td>Initial definition. Implemented in JavaScript 1.3.</td>
  </tr>
  <tr>
   <td>{{SpecName('ES5.1', '#sec-15.9.5.37', 'Date.prototype.setUTCDate')}}</td>
   <td>{{Spec2('ES5.1')}}</td>
   <td> </td>
  </tr>
  <tr>
   <td>{{SpecName('ES6', '#sec-date.prototype.setutcdate', 'Date.prototype.setUTCDate')}}</td>
   <td>{{Spec2('ES6')}}</td>
   <td> </td>
  </tr>
 </tbody>
</table>

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

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

<h2 id="See_also">相关内容</h2>

<ul>
 <li>{{jsxref("Date.prototype.getUTCDate()")}}</li>
 <li>{{jsxref("Date.prototype.setDate()")}}</li>
</ul>