The best way to get the current year is to use the
This method is defined on the
To get the current year, you can use the following code:
const date = new Date(); const currentYear = date.getFullYear(); console.log(currentYear);
getFullYear() method returns the current year in four digits. The method supports year values from 1000 to 9999.
Use the editor below to test out
getFullYear() in the browser.
Run button to see the result.
Hopefully, you found this content useful. Happy coding!
Leave us a message!