Using setFullYear with a year in the 0-99 range incorrectly adds 1900 to the year. For example, setFullYear(20) sets the year to 1920 instead of 20. The real setFullYear(20) correctly sets the year to 20 AD.
Reproduction
const timezoneMock = require("timezone-mock");
timezoneMock.register("UTC");
const d = new Date(2026, 0, 1);
d.setFullYear(20);
console.log(d.getFullYear()); // Expected: 20
timezoneMock.unregister();
| Version |
Result |
| Native |
20 |
| 1.3.6 |
20 |
| 1.4.0 & 1.4.1 |
1920 |
Using
setFullYearwith a year in the 0-99 range incorrectly adds 1900 to the year. For example,setFullYear(20)sets the year to 1920 instead of 20. The realsetFullYear(20)correctly sets the year to 20 AD.Reproduction
20201920