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!
If you want to learn about web development, founding a start-up, bootstrapping a SaaS, and more, follow me on Twitter! You can also join the conversation over at our official Discord!
Leave us a message!