Javascript Reference - JavaScript getFullYear() Method








getFullYear() returns the four-digit year (2007 instead of just 07).

Browser Support

getFullYear() Yes Yes Yes Yes Yes

Syntax

dateObject.getFullYear();

Parameters

None

Return Value

returns the four-digit year (2007 instead of just 07).





Example


var myDate = new Date();

console.log(myDate.getFullYear());

The code above generates the following result.

Example 2

In the following code getFullYear() method return the year for a specific date.


<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">get</button>
<p id="demo"></p>
<script>
function myFunction() {<!--from w  w  w  . j a  v  a2  s .  co  m-->
    var d = new Date("July 21, 1976 01:23:00");
    var n = d.getFullYear();
    document.getElementById("demo").innerHTML = n;
}
</script>

</body>
</html>

The code above is rendered as follows: