The getFullYear method in JavaScript retrieves the year from a given date according to the local time.
Syntax
The syntax for the getFullYear method is as follows:
Example
dateObj.getFullYear()
Return
A number the represents year.
JavaScript Date getFullYear method example
In this section, we will explore the getFullYear method by examining several examples.
Example 1
Let’s examine an illustration that demonstrates how to display the current year’s value.
Example
<script>
var year=new Date();
document.writeln(year.getFullYear());
</script>
Output:
Example 2
Let us examine an example that demonstrates how to extract the year from a specified date.
Example
<script>
var year=new Date("August 15, 1947 20:22:10");
document.writeln(year.getFullYear());
</script>
Output: