How to get the Current Year in JavaScript

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

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

Read Also  How to use WordPress Shortcodes in the Template