The getFullYear()
method in JavaScript returns the year of the specified date.
We declare the getFullYear()
method as shown below:
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.
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 Objectvar d = new Date();//getFullYear() Methodvar n = d.getFullYear();//Display the yearconsole.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 datevar d = new Date("April 25, 1999 23:15:00");//getFullYear() Methodvar n = d.getFullYear();//Displayconsole.log("Year:", n);
Free Resources