The getUTCFullYear method in JavaScript is utilized to retrieve the year from a designated date according to Coordinated Universal Time (UTC).
Syntax
The syntax for the getUTCFullYear method is illustrated as follows:
Example
dateObj.getUTCFullYear()
Return
A number that represents the year.
JavaScript Date getUTCFullYear method example
In this section, we will explore the getUTCFullYear method by examining multiple examples.
Example 1
Let’s examine an example that demonstrates how to output the current year based on Coordinated Universal Time (UTC).
Example
<script>
var year=new Date();
document.writeln("Year value : "+year.getUTCFullYear());
</script>
Output:
Output
Year value : 2018
Example 2
Let’s examine an example that demonstrates how to extract the year from a specified date in accordance with Universal Time.
Example
<script>
var year1=new Date("December 31, 1947 20:22:10 GMT+11:00");
var year2=new Date("December 31, 1947 20:22:10 GMT-11:00");
document.writeln("Year value1 : "+year1.getUTCFullYear()+"<br>");
document.writeln("Year value2 : "+year2.getUTCFullYear());
</script>
Output:
Output
Year value1 : 1947
Year value2 : 1948