The Wayback Machine - https://web.archive.org/web/20250307203102/https://www.geeksforgeeks.org/javascript-date-getfullyear-method/
Open In App

JavaScript Date getFullYear() Method

Last Updated : 16 Jul, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Share
Report
News Follow

The JavaScript Date getFullYear() Method is used to fetch the year from a given Date object.

Syntax:

DateObj.getFullYear()

Parameters:

This function does not accept any parameters.

Return Values:

It returns the year for the given date.

Example 1: This example shows the use of Date getFullYear() Method.

javascript
// Here a date has been assigned
// while creating Date object
let dateobj = new Date('October 15, 1996 05:35:32');

// Year from above date object is
// being fetched using getFullYear().
let B = dateobj.getFullYear();

// Printing year
console.log(B);

Output: 

1996

Example 2: If nothing as a parameter is given to the Date() constructor, then the getFullYear() function returns the current year. 

javascript
// Creating Date Object
let dateobj = new Date();

// Year from above object
// is being fetched using getFullYear().
let B = dateobj.getFullYear();

// Printing current year
console.log(B);

Output: 

2022

Example 3: The date of the month must lie between 1 to 31 because a month cannot have more than 31 days. That is why it returns NaN i.e, not a number because the date for the month does not exist. Hence, the Year will not exist when the date of the month is set as 45 or any number which does not lie between 1 to 31.

javascript
// Here a date has been assigned
// while creating Date object
let dateobj = new Date('October 45, 1996 05:35:32');

// Year from above date object is
// being fetched using getFullYear().
let B = dateobj.getFullYear();

// Printing year
console.log(B);

Output: 

NaN

Example 4: It has applications such as getting the current year. It is used on websites to validate the age of the user. 

javascript
// Creating Date Object
let dateobj = new Date();

// Year from above object
// is being fetched using getFullYear()
let B = dateobj.getFullYear();

// Printing current year
console.log(B);

Output: 

2022

We have a complete list of Javascript Date Objects, to check those please go through this Javascript Date Object Complete referencearticle.

Supported Browsers:

  • Google Chrome 1 and above
  • Edge 12 and above
  • Firefox 1 and above
  • Opera 4 and above
  • Safari 1 and above

JavaScript Date getFullYear() Method- FAQs

What is the getFullYear() method in JavaScript?

The getFullYear() method returns the four-digit year of the specified date according to local time.

What does getFullYear return?

getFullYear returns the four-digit year of the specified date according to local time. For example, new Date().getFullYear() might return 2024.

How do you use the getFullYear() method?

let year = new Date().getFullYear(); // Example output: 2024

Does getFullYear() account for time zones?

Yes, it returns the year according to the local time zone of the environment where the code is executed.

Can getFullYear() handle dates before the year 2000?

Yes, getFullYear() returns the full year even for dates before the year 2000, such as 1985 for a date in 1985.

We have a Cheat Sheet on Javascript where we covered all the important topics of Javascript to check those please go through Javascript Cheat Sheet-A Basic guide to JavaScript.


Next Article

Similar Reads

three90RightbarBannerImg