Get Current Year In Javascript Using getFullYear() Method

Sameer Saini May 04, 2022
Get Current Year In Javascript Using getFullYear() Method

Do you want to get the current year (e.g: 2021, 2022) from the date object in JavaScript?

In Javascript, we can make use of the getFullYear() method that is available on the Date() object.

In this blog post, we will learn how we can get the current year and for that matter any year from a data object in javascript.

 

 

Get Current Year In Javascript

To get the current year, we would first have to create a new date object.

This new date object would give us the current date of client.

Using this current date, we will get the year value by usnig the getFullYear method available on the date object.

Let's see this in an example.

 

Example:

 

Result:

Get current year in javascript

 

 

Get Year From Any Date In Javascript

In the last example, we saw how we could get the current year from the current date.

But what if you want to get the year from any date in javascript?

In the following example, we will learn that because the method .getFullYear() is on the date object, you can pass in a date of your choice.

 

Example:

 

Result:

Get year from date in javascript