JavaScript .getUTCFullYear()
The .getUTCFullYear() method is a built-in function in JavaScript that returns the year of the specified date according to universal time. It extracts the four-digit year (e.g. 2023) from a given Date object, based on the Coordinated Universal Time (UTC) time zone.
This method is particularly useful when it’s necessary to retrieve the year component of a date regardless of the time zone or local system settings. It ensures consistent results regardless of the user’s geographical location.
Syntax
const date = new Date();
result = date.getUTCFullYear();
A Date object is used for working with dates and times. The object provides a way to create, manipulate, and format dates in various formats.
A Date object can be created by declaring a new variable with the new Date() constructor.
Example
Consider the following example that demonstrates the usage of the .getUTCFullYear() method:
const date = new Date('2023-06-06T10:30:00Z');const year = date.getUTCFullYear();console.log(year);
This example results in the following output:
2023
Codebyte Example
The example below is a runnable code example that defines jsOfficialRelease as a new Date object with the official release date of Javascript. Then, a console log using the .getUTCFullYear() method displays the release year:
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn JavaScript on Codecademy
- Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.
- Beginner Friendly.15 hours