Get the Current Year using JavaScript


Borislav Hadzhiev

Last updated: Oct 24, 2021


Photo from Unsplash

Get the Current Year in JavaScript #

To get the current year in JavaScript, call the new Date() constructor to get a date object and call the getFullYear() method on the result, e.g. new Date().getFullYear(). The getFullYear method will return a number corresponding to the current year.

// 👇️ Get current Year const currentYear = new Date().getFullYear(); console.log(currentYear); // 👇️ Get year of specific date const date = new Date('January 04, 2025 05:24:07'); const yearOfDate = date.getFullYear(); // 👉️ 2025

We used the Date() constructor to get a Date object, on which we can call various methods.

For our use case, we called the Date.getFullYear method, which returns a number representing the year that corresponds to the current date.

Other commonly used methods on the Date object are:

  • Date.getMonth - returns an integer between 0 (January) and 11 (December) and represents the month for a given date. Yes, unfortunately the getMonth method is off by 1.
  • Date.getDate - returns the day of the month for a specific date

These methods allow you get the year / month / day for any date object, it doesn't have to be the current year.

All you have to do is pass the specific date into the Date constructor on which you call the methods.

const date = new Date('December 24, 2025 05:24:07'); const yearOfDate = date.getFullYear(); // 👉️ 2025 const monthOfDate = date.getMonth() + 1; // 12 const dayOfMonth = date.getDate(); // 24

Further Reading #

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.