MDN self-hosted library · e01.org

Date.prototype.getYear()

Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.

js
const xmas = new Date("1995-12-25");
const year = xmas.getYear(); // returns 95
js
const xmas = new Date("2000-12-25");
const year = xmas.getYear(); // returns 100
js
const xmas = new Date("1800-12-25");
const year = xmas.getYear(); // returns -100
js
const xmas = new Date("2015-12-25");
xmas.setYear(95);
const year = xmas.getYear(); // returns 95