JavaScript | date.getYear() Function
The date.getYear() method in JavaScript is use to get the year in a specified date according to universal time. The year we get from the method getYear() is the current year minus 1900.
Syntax:
date.getYear()
Here, date is the object of Date() class.
Parameter: This function does not accept any parameters.
Return Value: This method returns a value which is subtracted from 1900 to current year.
Example 1: This example returns the year of the specified date according to universal time.
<script> // "date" is object of Date() class var date = new Date(); // Use "getYear()" method and stroes // the returned value to "n" var n = date.getYear(); // Display the result document.write("The value returned by getYear() method: " + n) </script> |
Output:
The value returned by getYear() method: 119
Example 2: This example only send the year to the constructor.
<script> // Year 2000 is assign to the // constructor of Date() class var date = new Date('2000') // Use "getYear()" method and stroes // the returned value to "n" var n = date.getYear(); // Display the returned value // The value is the subtraction of // 2000 and 1900 document.write("The value returned by getYear() method: " + n) </script> |
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.
<script> // Full date is assign to the constructor of Date() class var date = new Date('October 15, 2010, 02:05:32') // Use "getYear()" method and stroes the // returned value in "n" var n = date.getYear(); // Display the returned value // The value is the subtraction of 2010 and 1900 document.write("The value returned by getYear() method: " + n) </script> |
Output:
The value returned by getYear() method: 110
Recommended Posts:
- How to call a function that return another function in JavaScript ?
- Javascript | Number() Function
- JavaScript | toExponential() Function
- JavaScript | Math.pow( ) Function
- JavaScript | Array.of() function
- JavaScript | toFixed( ) Function
- JavaScript | Symbol.for() function
- JavaScript | Math.E() function
- What is the inline function in JavaScript ?
- JavaScript | Math.abs( ) function
- JavaScript | toPrecision( ) Function
- JavaScript | toString( ) function
- JavaScript | Function Call
- How to override a JavaScript function ?
- JavaScript | Function Parameters
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



