getUTCFullYear()
Returns the four-digit year of the UTC date value.
UTC time is the same as GMT time.
getUTCFullYear() |
Yes | Yes | Yes | Yes | Yes |
dateObject.getUTCFullYear();
None.
return a number, representing the year (four digits).
var myDate = new Date();
console.log(myDate.getUTCFullYear());
The code above generates the following result.
The following code returns the UTC year of a specific date.
<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {<!-- ww w. j ava2 s.c om-->
var d = new Date("July 12, 1976 01:23:00");
var n = d.getUTCFullYear();
document.getElementById("demo").innerHTML = n;
}
</script>
</body>
</html>
The code above is rendered as follows: