What is getFullYear() in JavaScript?

The getFullYear() method in JavaScript returns the year of the specified date.

Syntax

We declare the getFullYear() method as shown below:

Parameters and return value

The getFullYear() method does not take any parameters. Instead, it returns an absolute four-digit value. The year returned is a value between 1000 and 9999.

Examples

The following code shows the use of the getFullYear() method in JavaScript.

First, we declare a new Date object with the current date and time. We then use the getFullYear() method to get the whole year:

//Date Object
var d = new Date();
//getFullYear() Method
var n = d.getFullYear();
//Display the year
console.log("Year:", n);

In the example below, we declare the new Date object with a specified date. The getFullYear() method returns the year 1999:

//Date Object with a specified date
var d = new Date("April 25, 1999 23:15:00");
//getFullYear() Method
var n = d.getFullYear();
//Display
console.log("Year:", n);

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved