pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Date/setYear

ttps://developer.mozilla.org/favicon.svg" />

此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。

View in English Always switch to English

Date.prototype.setYear()

已弃用: 不再推荐使用该特性。虽然一些浏览器仍然支持它,但也许已从相关的 web 标准中移除,也许正准备移除或出于兼容性而保留。请尽量不要使用该特性,并更新现有的代码;参见本页面底部的兼容性表格以指导你作出决定。请注意,该特性随时可能无法正常工作。

setYear() 方法根据一个本地时间为一个确定的日期对象设置年份。由于setYear() 并不设置完整年份("正是千年虫问题"),本方法已经完全被setFullYear() 方法所取代。

语法

dateObj.setYear(yearValue)

参数

yearValue

一个整数。

返回值

介于 1970 年 1 月 1 日 00:00:00 UTC 时间与更新后日期的毫秒数。

描述

如果yearValue 是介于 0 到 99(包含 99) 之间的整数,则目标对象 dateObj 的年份被设置为 1900 + yearValue。否则,目标对象 dateObj 的年份被设置为 yearValue.

示例

使用 setYear()

例子前两行(除去声明)将年份设置为 1996。第三行将年份设置为 2000.

js
var theBigDay = new Date();

theBigDay.setYear(96);
theBigDay.setYear(1996);
theBigDay.setYear(2000);

规范

Specification
ECMAScript® 2026 Language Specification
# sec-date.prototype.setyear

浏览器兼容性

参见

pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy