How to get the Current Year in JavaScript

avatar

Borislav Hadzhiev

Sun Oct 24 20211 min read

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.

index.js
// ๐Ÿ‘‡๏ธ 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.

index.js
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 #

Join my newsletter

I'll send you 1 email a week with links to all of the articles I've written that week

Buy Me A Coffee