JavaScript Date getFullYear() Method

JavaScript Date getFullYear() method returns the year for this date according to local time. The getFullYear() method returns an absolute number.

Syntax

Date.getFullYear()

Parameters

It does not take any parameters.

Return value

It is an integer representing the year for the given date according to local time. Returns NaN if the date is invalid.

Example 1: Usage of Date getFullYear()

let dtObj = new Date('September , 1993 16:30:32');
 
let data = dtObj.getFullYear();

console.log(data);

Output

1993

Example 2: Passing no parameter

let dtObj = new Date();
 
let data = dtObj.getFullYear();

console.log(data);

Output

2023

Example 3: Returning NaN

let dtObj = new Date('September 32, 1993 05:35:32');
 
let data = dtObj.getFullYear();

console.log(data);

Output

NaN

Browser Compatibility

Chrome Edge Firefox Safari Opera IE
Yes Yes Yes Yes Yes Yes

That’s it!

Related posts

JavaScript Date getDate()

JavaScript Date setDate()

JavaScript Date getDay()