JavaScript Date getYear() Method


Advertisements


Description

Javascript date getYear() method returns the year in the specified date according to universal time. The getYear is no longer used and has been replaced by the getYear method.

The value returned by getYear is the current year minus 1900. JavaScript 1.2 and earlier versions return either a 2-digit or 4-digit year. For example, if the year is 2026, the value returned is 2026. So before testing this function, you need to be sure of the javascript version you are using.

Syntax

Its syntax is as follows −

>
Date.getYear()

Return Value

Returns the year in the specified date according to universal time.

Example

Try the following example.

<html>

   <head>
      <title>JavaScript getYear Method</title>
   </head>
   
   <body>
      
      <script type="text/javascript">
         var dt = new Date();
         document.write("getYear() : " + dt.getYear() ); 
      </script>
      
   </body>
</html>

Output

getYear() : 208

javascript_date_object.htm