aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/javascript/reference/global_objects/date/setyear
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/setyear
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/setyear')
-rw-r--r--files/zh-cn/web/javascript/reference/global_objects/date/setyear/index.html72
1 files changed, 72 insertions, 0 deletions
diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/setyear/index.html b/files/zh-cn/web/javascript/reference/global_objects/date/setyear/index.html
new file mode 100644
index 0000000000..7999ad0022
--- /dev/null
+++ b/files/zh-cn/web/javascript/reference/global_objects/date/setyear/index.html
@@ -0,0 +1,72 @@
+---
+title: Date.prototype.setYear()
+slug: Web/JavaScript/Reference/Global_Objects/Date/setYear
+tags:
+ - JavaScript
+ - 已废弃
+ - 日期
+translation_of: Web/JavaScript/Reference/Global_Objects/Date/setYear
+---
+<div>{{JSRef}} {{deprecated_header}}</div>
+
+<p><strong><code>setYear()</code></strong> 方法根据一个本地时间为一个确定的日期对象设置年份。由于<code>setYear()</code> 并不设置完整年份("正是千年虫问题"),本方法已经完全被{{jsxref("Date.prototype.setFullYear()","setFullYear()")}} 方法所取代。</p>
+
+<h2 id="语法">语法</h2>
+
+<pre class="syntaxbox"><code><var>dateObj</var>.setYear(<var>yearValue</var>)</code></pre>
+
+<h3 id="参数">参数</h3>
+
+<dl>
+ <dt><code>yearValue</code></dt>
+ <dd>一个整数。</dd>
+</dl>
+
+<h3 id="返回值">返回值</h3>
+
+<p>介于1970年1月1日 00:00:00 UTC时间与更新后日期的毫秒数。</p>
+
+<h2 id="描述">描述</h2>
+
+<p>如果<code>yearValue</code> 是介于0到99(包含99)之间的整数,则目标对象 <code>dateObj</code> 的年份被设置为 <code>1900 + yearValue</code>。否则,目标对象 <code>dateObj</code> 的年份被设置为 <code>yearValue</code>.</p>
+
+<h2 id="例子">例子</h2>
+
+<h3 id="使用_setYear">使用 <code>setYear()</code></h3>
+
+<p>例子前两行(除去声明)将年份设置为1996。 第三行将年份设置为2000.</p>
+
+<pre class="brush: js">var theBigDay = new Date();
+
+theBigDay.setYear(96);
+theBigDay.setYear(1996);
+theBigDay.setYear(2000);
+</pre>
+
+<h2 id="规范">规范</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">规范</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('ESDraft', '#sec-date.prototype.setyear', 'Date.prototype.setYear')}}</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.setYear")}}</p>
+
+<h2 id="相关链接">相关链接</h2>
+
+<ul>
+ <li>{{jsxref("Date.prototype.getFullYear()")}}</li>
+ <li>{{jsxref("Date.prototype.getUTCFullYear()")}}</li>
+ <li>{{jsxref("Date.prototype.setFullYear()")}}</li>
+ <li>{{jsxref("Date.prototype.setUTCFullYear()")}}</li>
+</ul>