Home  »  ArticlesGuidesProgrammingSnippetsTechnology   »   How to get the Current Year in JavaScript

How to get the Current Year in JavaScript

To get the current year in JavaScript, we will use the built-in Date object. This JavaScript Date object is used to handle all the Date and time-related operations.

In this example, we will use the getFullYear() method. It will return the year of the specified date according to local time. This method returns a four-digit number representing the year.

Current Year in JavaScript Snippet

let date =  new Date().getFullYear();
console.log(date);

Note: Here we use getFullYear(), not getYear(), as the latter is deprecated.

Found this article interesting? Follow Brightwhiz on Facebook, Twitter, and YouTube to read and watch more content we post.