JavaScript getUTCFullYear() | Get the UTC Year

The JavaScript getUTCFullYear() method is used to get the year according to Universal Time Coordinated (UTC) or Greenwich Mean Time (GMT). For example:

HTML with JavaScript Code
<!DOCTYPE html>
<html>
<body>
   
   <p id="xyz"></p>

   <script>
      const d = new Date();
      let year = d.getUTCFullYear();
      document.getElementById("xyz").innerHTML = year;
   </script>

</body>
</html>
Output

JavaScript getUTCFullYear() Syntax

The syntax of getUTCFullYear() method in JavaScript is:

x.getUTCFullYear()

where x must be an object of the Date() constructor.

The getUTCFullYear() method returns a number from 1000 to 9999.

Get Last Two Digits of the UTC Year in JavaScript

HTML with JavaScript Code
<!DOCTYPE html>
<html>
<body>
   
   <p id="xyz"></p>

   <script>
      const d = new Date();
      let year = d.getUTCFullYear();
      document.getElementById("xyz").innerHTML = year.toString().slice(-2);
   </script>

</body>
</html>
Output

Please note: The toString() method converts a number to string.

Please note: The slice() method slice required part of a defined string. For example: myString.slice(-2) slice the last two characters of the string.

JavaScript Online Test


« Previous Tutorial Next Tutorial »



Like/Share Us on Facebook 😋