The getFullYear() method returns the year of a date as a four digit number:

Example

const d = new Date();
document.getElementById("demo").innerHTML = d.getFullYear();



Practice Excercise Practice now