W3docs

How Get the Current Year in JavaScript

Read this tutorial and learn about the simplest and fastest method of getting the current year a four-digit number using the Date object in JavaScript.

To get the current year, you can call the getFullYear() method, which will return the year of the specified Date according to local time. The value returned by it is a number. For the dates between 1000 and 9999 years, the <kbd class="highlighted">getFullYear()</kbd> method returns a four-digit number.

Create a new Date() object and invoke the <kbd class="highlighted">getFullYear()</kbd> method to return the current year:

Javascript create new date and invoke getFullYear() method

javascript— editable
Danger

It is important to use <kbd class="highlighted">getFullYear()</kbd>, not <kbd class="highlighted">getYear()</kbd>, as it is deprecated and can return a 2-digit year at times.

Also check How to Get the Current Date and Time in JavaScript

Date and Time

There is a built-in Date object to handle all date and time-related operations. You can use the Date object to display the current date and time, create a calendar, build a timer, etc. The new operator is used to create a Date object.