How to get the only current year in JavaScript?

JavascriptWeb DevelopmentFront End Technology

To get an only current year, use the JavaScript getFullYear() method. JavaScript date getFullYear() method returns the year of the specified date according to local time. The value returned by getFullYear() is an absolute number. For dates between the years 1000 and 9999, getFullYear() returns a four-digit number, for example, 2008.

Example

You can try to run the following code to get a current year in JavaScript −

Live Demo

<html>
   <head>
      <title>JavaScript getFullYear Method</title>
   </head>
   <body>
      <script>
         var dt = new Date("December 30, 2017 23:15:00");
         document.write("getFullYear() : " + dt.getFullYear() );
      </script>
   </body>
</html>

Output

getFullYear() : 2017
raja
Published on 13-Feb-2018 09:13:43
Advertisements