Anjan Dutta
How to get the current year in JavaScript
How to get the current year in JavaScript
Published On: 03/11/2021
To get the current year in JavaScript, we can use the getFullYear()
function.
The getFullYear()
function works on a date object.
So, to get the current year, we can apply this function on the new date()
function like below.
console.log((new Date()).getFullYear());
// current year will be printed
The new Date()
will return today\'s date and getFullYear()
will retrieve the four digit year from the date.