JavaScript Date getUTCFullYear()
Syntax & Examples


Date.getUTCFullYear() method

The getUTCFullYear() method of the Date object in JavaScript returns the year (4 digits for 4-digit years) in the specified date according to universal time.


Syntax of Date.getUTCFullYear()

The syntax of Date.getUTCFullYear() method is:

getUTCFullYear()

This getUTCFullYear() method of Date returns the year (4 digits for 4-digit years) in the specified date according to universal time.

Return Type

Date.getUTCFullYear() returns value of type Number.



✐ Examples

1 Using getUTCFullYear() to get the UTC year of a specific date

In JavaScript, we can use the getUTCFullYear() method to get the year from a Date object according to universal time.

For example,

  1. We create a new Date object date representing January 15, 2021.
  2. We use the getUTCFullYear() method to get the year from date.
  3. The year is stored in the variable utcYear.
  4. We log utcYear to the console using console.log() method.

JavaScript Program

const date = new Date('2021-01-15');
const utcYear = date.getUTCFullYear();
console.log(utcYear);

Output

2021

2 Using getUTCFullYear() with the current date

In JavaScript, we can use the getUTCFullYear() method to get the current year from the current date according to universal time.

For example,

  1. We create a new Date object now representing the current date and time.
  2. We use the getUTCFullYear() method to get the current year from now.
  3. The current year is stored in the variable currentUTCYear.
  4. We log currentUTCYear to the console using console.log() method.

JavaScript Program

const now = new Date();
const currentUTCYear = now.getUTCFullYear();
console.log(currentUTCYear);

Output

2024

3 Using getUTCFullYear() with a specific date in the past

In JavaScript, we can use the getUTCFullYear() method to get the year from a specific date in the past according to universal time.

For example,

  1. We create a new Date object pastDate representing July 4, 1776.
  2. We use the getUTCFullYear() method to get the year from pastDate.
  3. The year is stored in the variable pastUTCYear.
  4. We log pastUTCYear to the console using console.log() method.

JavaScript Program

const pastDate = new Date('1776-07-04');
const pastUTCYear = pastDate.getUTCFullYear();
console.log(pastUTCYear);

Output

1776

Summary

In this JavaScript tutorial, we learned about getUTCFullYear() method of Date: the syntax and few working examples with output and detailed explanation for each example.