Method
JavaScript Date getFullYear() Method
The JavaScript Date getFullYear() method is used to get the four-digit year of a specified date according to local time. The method returns the year in the range of 1000 to 9999.
Syntax
[dm_code_snippet background=”yes” background-mobile=”yes” slim=”no” line-numbers=”no” bg-color=”#abb8c3″ theme=”dark” language=”php” wrapped=”no” height=”” copy-text=”Copy Code” copy-confirmed=”Copied”]
dateObj.getFullYear()
[/dm_code_snippet]
Here, dateObj is a Date object.
Example
Let’s see an example of using the getFullYear() method.
[dm_code_snippet background=”yes” background-mobile=”yes” slim=”no” line-numbers=”no” bg-color=”#abb8c3″ theme=”dark” language=”php” wrapped=”no” height=”” copy-text=”Copy Code” copy-confirmed=”Copied”]
var today = new Date(); var year = today.getFullYear(); document.write(year);
[/dm_code_snippet]
Output:
[dm_code_snippet background=”yes” background-mobile=”yes” slim=”no” line-numbers=”no” bg-color=”#abb8c3″ theme=”dark” language=”php” wrapped=”no” height=”” copy-text=”Copy Code” copy-confirmed=”Copied”]
2019
[/dm_code_snippet]
Browser Support
The getFullYear() method is supported in all major browsers.
Return Value
The getFullYear() method returns the year (a four-digit number) of a specified date according to local time.