How to use getYear in JavaScript

In this article, I will explain use of getYear() method in JavaScript date object.
  • 2159

JavaScript date getYear() method

  • getYear() method of date object returns the year in the specified date according to universal time or local time.
  • getYear() has been replaced by the getFullYear method.

The getyear method returns the year minus 1900; thus:

  • getYear() method is returned 100 or greater, If year above 2000. For example, getYear() returns 106 if the year is 2006.
  • getYear() method is returned value between 0 and 99, If year between 1900 and 1999. For example, getYear() returns 86 if the year is 1986
  • getYear() method is returned value less than 0, If year less than 1900 or greater than 1999. For example, getYear() returns -100 if the year is 1700.
  • getYear() method is returned value less than 0, If year less than 1900 or greater than 1999. For example, getYear() returns -100 if the year is 1800.
  • Date.getfullyear use instead of getYear so that the year is specified in full.

Syntax

Date.getYear()

Example

In the following example show to how the getYear() method can be used.

<html>

<head>

<title>JavaScript getYear Method</title>

</head>

<body>

<h3 style="color:ActiveCaption">JavaScript getYear() Method Example</h3>

<script type="text/javascript">

    var dt = new Date();

    document.write("getYear(): " + dt.getYear());

</script>

</body>

</html>

Output

getYear method.jpg

You may also want to read these related articles here

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.