getFullYear()
returns the
four-digit year (2007 instead of just 07).
getFullYear() |
Yes | Yes | Yes | Yes | Yes |
dateObject.getFullYear();
None
returns the four-digit year (2007 instead of just 07).
var myDate = new Date();
console.log(myDate.getFullYear());
The code above generates the following result.
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: