JavaScript Date getUTCFullYear() Method



The JavaScript Date getUTCFullYear() method is used to retrieve the "full year" for the date (according to the universal time). The return value will be the year component of the date object's UTC time. If the date is invalid, this method returns Not a Number (NaN) as result. Additionally, this method does not accept any parameters.

Coordinated Universal Time (UTC) is the primary time standard by which the world regulates clocks and time. Whereas, the India Standard Time (IST) is the time observed in India, and the time difference between IST and UTC is as UTC+5:30 (i.e. 5 hours 30 minutes).

Syntax

Following is the syntax of JavaScript Date getUTCFullYear() method −

getUTCFullYear();

This method does not accept any parameters.

Return Value

This method returns a 4-digit integer representing the year in UTC (Coordinated Universal Time) of the specified date.

Example 1

In the following example, we are demonstrating the basic usage of JavaScript Date getUTCFullYear() method −

<html>
<body>
<script>
   const currentDate = new Date();
   const year = currentDate.getUTCFullYear();

   document.write(year);
</script>
</body>
</html>

Output

The above program returns the "full year" according to UTC.

Example 2

Here, we are retrieving full year for the specific date "December 31, 2020" −

<html>
<body>
<script>
   const specificDate = new Date('2020-12-31 11:00:00');
   const year = specificDate.getUTCFullYear();

   document.write(year);
</script>
</body>
</html>

Output

The above programs returns integer "2020" as the full year for given date.

Example 3

In this example, a custom date is created using the Date constructor, and getUTCFullYear() is used to obtain the year in UTC for that specific date and time.

<html>
<body>
<script>
   const customDate = new Date(1995, 11, 17, 3, 24, 0); // December 17, 1995, 03:24:00
   const year = customDate.getUTCFullYear();

   document.write(year);
</script>
</body>
</html>

Output

As we can see the output, "1995" is returned as current year.