JavaScript Date getFullYear() method - JavaScript Tutorial

JavaScript Date getFullYear() method

BLUF: This tutorial on JavaScript Date getFullYear() 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 getFullYear() method

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

The getFullYear method in JavaScript retrieves the year from a given date according to the local time.

Syntax

The syntax for the getFullYear method is as follows:

Example

dateObj.getFullYear()

Return

A number the represents year.

JavaScript Date getFullYear method example

In this section, we will explore the getFullYear method by examining several examples.

Example 1

Let’s examine an illustration that demonstrates how to display the current year’s value.

Example

<script>
var year=new Date();
document.writeln(year.getFullYear());
</script>

Output:

Example 2

Let us examine an example that demonstrates how to extract the year from a specified date.

Example

<script>
var year=new Date("August 15, 1947 20:22:10");
document.writeln(year.getFullYear());
</script>

Output:

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