How to get current year in JavaScript

#javascript #date

Last updated on Jul 6, 2022 by Suraj Sharma



In this tutorial, you will learn to get the current year using the JavaScript's Date object.


Get Current Year


To get the current year in JavaScript, we will use the getFullYear() method available in the Date object. It returns the year in ‘YYYY’ format.


Solution


const date = new Date()
currentYear = date.getFullYear()

console.log(currentYear) // "2022"


Related Solutions


Rate this post


Suraj Sharma is a Full Stack Software Engineer. He holds a B.Tech degree in Computer Science & Engineering from NIT Rourkela.