JavaScript Date getUTCFullYear()

Posted by

Method

JavaScript Date getUTCFullYear() Method

The getUTCFullYear() method is a JavaScript Date method that will return the year for the specified date according to universal time. It is used to get the four-digit year of a specified date according to universal time (UTC). The getUTCFullYear() method returns the 4-digit year of a date as per universal time (UTC).

Syntax

The syntax for the getUTCFullYear() method is given below:

[dm_code_snippet background=”yes” background-mobile=”yes” slim=”no” line-numbers=”no” bg-color=”#abb8c3″ theme=”dark” language=”php” wrapped=”no” height=”” copy-text=”Copy Code” copy-confirmed=”Copied”]

dateObj.getUTCFullYear()

[/dm_code_snippet]

The syntax contains one parameter:

  • dateObj – The specified date object.

Return Value

The getUTCFullYear() method returns the four-digit year for the specified date according to universal time.

Browser Support

The getUTCFullYear() method is supported in all major browsers, including:

  • Google Chrome
  • Internet Explorer
  • Mozilla Firefox
  • Safari
  • Opera

Example

The following example demonstrates the use of the getUTCFullYear() method:

[dm_code_snippet background=”yes” background-mobile=”yes” slim=”no” line-numbers=”no” bg-color=”#abb8c3″ theme=”dark” language=”php” wrapped=”no” height=”” copy-text=”Copy Code” copy-confirmed=”Copied”]

<script type="text/javascript">
   var d = new Date();
   document.write(d.getUTCFullYear());
</script>

[/dm_code_snippet]

The code above will output the four-digit year according to universal time (UTC).

The output of the code above will be:

[dm_code_snippet background=”yes” background-mobile=”yes” slim=”no” line-numbers=”no” bg-color=”#abb8c3″ theme=”dark” language=”php” wrapped=”no” height=”” copy-text=”Copy Code” copy-confirmed=”Copied”]

2018

[/dm_code_snippet]