Deprecated
This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.
Метод setYear()
встановлює рік для вказаної дати згідно з місцевим часом. Оскільки setYear()
не встановлює повне значення року ("проблема 2000 року"), він більше не використовується та був замінений на метод setFullYear()
.
Синтаксис
dateObj.setYear(yearValue)
Параметри
yearValue
- Ціле число.
Повертає
Кількість мілісекунд між 1 січня 1970 року 00:00:00 за UTC та оновленою датою.
Опис
Якщо yearValue
є числом між 0 та 99 (включно), тоді рік для dateObj
встановлюється як 1900 + yearValue
. Інакше, рік для dateObj
встановлюється як yearValue
.
Приклади
Використання setYear()
Перші два рядки встановлюють значенням року 1996. Третій встановлює рік 2000.
var theBigDay = new Date();
theBigDay.setYear(96);
theBigDay.setYear(1996);
theBigDay.setYear(2000);
Специфікації
Сумісність з веб-переглядачами
BCD tables only load in the browser
The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.