A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/javascript/javascript-date-getyear-method/ below:

JavaScript Date getYear() Method - GeeksforGeeks

JavaScript Date getYear() Method

Last Updated : 12 Jul, 2025

JavaScript date.getYear() is used to get the year on a specified date according to universal time. The year we get from the method getYear() is the current year minus 1900.

Syntax:
date.getYear();
Parameters: Return Value:

Example 1: This example returns the year of the specified date according to universal time.

JavaScript
// "date" is object of Date() class
let date = new Date();

// Use "getYear()" method and stores 
// the returned value to "n"
let n = date.getYear();

// Display the result
console.log("The value returned by getYear() method: " + n)

Output:

The value returned by getYear() method: 119

Example 2: This example only sends the year to the constructor.

JavaScript
// Year 2000 is assign to the 
// constructor of Date() class
let date = new Date('2000')
  
// Use "getYear()" method and stores
// the returned value to "n"
let n = date.getYear();
  
// Display the returned value
// The value is the subtraction of
// 2000 and 1900   
console.log("The value returned by getYear() method: " + n)

Output:

The value returned by getYear() method: 100

Example 3: Here, we pass a full date to the constructor, the format of the date is month-day-year-time, such as October 15, 2010, 02:05:32.

JavaScript
// Full date is assign to the constructor of Date() class
let date = new Date('October 15, 2010, 02:05:32')

// Use "getYear()" method and stores the
// returned value in "n"     
let n = date.getYear();
  
// Display the returned value
// The value is the subtraction of 2010 and 1900   
console.log("The value returned by getYear() method: " + n)

Output
The value returned by getYear() method: 110
Supported Browsers:

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4