A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developer.cdn.mozilla.net/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setYear below:

Date.prototype.setYear() - JavaScript | MDN

Date.prototype.setYear()

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.

The setYear() method of Date instances sets the year for a specified date according to local time.

However, the way the legacy setYear() method sets year values is different from how the preferred setFullYear() method sets year values — and in some cases, also different from how new Date() and Date.parse() set year values. Specifically, given two-digit numbers, such as 22 and 61:

Because of those differences in behavior, you should no longer use the legacy setYear() method, but should instead use the preferred setFullYear() method.

Syntax Parameters Return value

Changes the Date object in place, and returns its new timestamp. If yearValue is NaN (or other values that get coerced to NaN, such as undefined), the date is set to Invalid Date and NaN is returned.

Description

If yearValue is a number between 0 and 99 (inclusive), then the year for dateObj is set to 1900 + yearValue. Otherwise, the year for dateObj is set to yearValue.

Examples Using setYear()

The first two lines set the year to 1996. The third sets the year to 2000.

const theBigDay = new Date();

theBigDay.setYear(96);
theBigDay.setYear(1996);
theBigDay.setYear(2000);
Specifications Browser compatibility See also

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4