JavaScript Date getUTCFullYear() method - JavaScript Tutorial

JavaScript Date getUTCFullYear() method

BLUF: This tutorial on JavaScript Date getUTCFullYear() method provides an in-depth look at JavaScript's core features. It includes practical examples and code snippets to help you master modern JS development.
Key Discovery: JavaScript Date getUTCFullYear() method

Understanding JavaScript Date getUTCFullYear() method is crucial for building dynamic, interactive web applications. Explore the examples below to see it in action.

The getUTCFullYear method in JavaScript is utilized to retrieve the year from a designated date according to Coordinated Universal Time (UTC).

Syntax

The syntax for the getUTCFullYear method is illustrated as follows:

Example

dateObj.getUTCFullYear()

Return

A number that represents the year.

JavaScript Date getUTCFullYear method example

In this section, we will explore the getUTCFullYear method by examining multiple examples.

Example 1

Let’s examine an example that demonstrates how to output the current year based on Coordinated Universal Time (UTC).

Example

<script>

var year=new Date();

document.writeln("Year value : "+year.getUTCFullYear());

</script>

Output:

Output

Year value : 2018

Example 2

Let’s examine an example that demonstrates how to extract the year from a specified date in accordance with Universal Time.

Example

<script>

var year1=new Date("December 31, 1947 20:22:10 GMT+11:00");

var year2=new Date("December 31, 1947 20:22:10 GMT-11:00");

document.writeln("Year value1 : "+year1.getUTCFullYear()+"<br>");

document.writeln("Year value2 : "+year2.getUTCFullYear());

</script>

Output:

Output

Year value1 : 1947

Year value2 : 1948

Input Required

This code uses input(). Please provide values below:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience