From http://www.w3schools.com (Copyright Refsnes Data)
The getYear() method should not be used. Use the getFullYear() method instead!
JavaScript Date Object
The getYear() method returns the year, as a two-digit OR a three/four-digit number.
The value returned by getYear() is not always four digits. For years between 1900 and 1999 the getYear() method returns only two digits.
For other years (before 1900 and after 1999) the return is browsers dependant:
Internet Explorer:
Firefox:
| dateObject.getYear() |
Note: This method is always used in conjunction with a Date object.
Important: The getYear() method should no longer be used. Use the getFullYear() method instead!!
Example 1Get the current year:
The output of the code above will be: Try it yourself » |
Example 2Here we will extract the year out of the specific date:
The output of the code above will be:
Try it yourself » |
JavaScript Date Object
From http://www.w3schools.com (Copyright Refsnes Data)