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();
Parameter:
This function does not accept any parameters.
Return Value:
This method returns a value that is subtracted from 1900 to the current year.
Example 1: This example returns the year of the specified date according to universal time.
Javascript
let date = new Date();
let n = date.getYear();
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
let date = new Date('2000')
let n = date.getYear();
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
let date = new Date('October 15, 2010, 02:05:32')
let n = date.getYear();
console.log("The value returned by getYear() method: " + n)
|
Output
The value returned by getYear() method: 110
Supported Browsers:
- Google Chrome
- Internet Explorer
- Mozilla Firefox
- Opera
- Safari
We have a complete list of Javascript Date Objects, to check those please go through this Javascript Date Object Complete reference article.
Learn to code easily with our course
Coding for Everyone. This course is accessible and designed for everyone, even if you're new to coding. Start today and join millions on a journey to improve your skills!Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Commit to GfG's Three-90 Challenge! Purchase a course, complete 90% in 90 days, and save 90% cost click here to explore.
Last Updated :
18 Dec, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...