Home >>JavaScript Date Object Methods >JavaScript getUTCFullYear() Method

JavaScript getUTCFullYear() Method

JavaScript getUTCFullYear() Method

The getUTCFullYear() method is an inbuilt method in JavaScript which returns the year (between 1000 and 9999) for the specified date on the basis of universal time. The UTC method assuming that the date object is of local time and date.

Syntax:

Date.getUTCFullYear()

Browser Support

Method Chrome Edge Firefox Safari Opera
getUTCFullYear() Yes Yes Yes Yes Yes

Here is an example of JavaScript getUTCFullYear() Method:

<html>
<body>
<button onclick="myGetFullYear()">click me</button>
<p id="Getyear"></p>
<script>
function myGetFullYear() 
{
  var d = new Date();
  var x = d.getUTCFullYear();
  document.getElementById("Getyear").innerHTML = x;
}
</script>
</body>
</html>
Output:

 

Example 2:

<html>
<body>
<script>
var year1=new Date("December 31, 1997 20:22:10 GMT+12:00");
var year2=new Date("December 31, 1997 20:22:10 GMT-12:00");
document.writeln("First Year value : "+year1.getUTCFullYear()+"<br>");
document.writeln("Second Year value : "+year2.getUTCFullYear());
</script>
</body>
</html>
Output: