Skip to content
Related Articles

Related Articles

How to get the current year using JavaScript ?
  • Last Updated : 14 Sep, 2020

The purpose of this article is to get the current year by using JavaScript getFullYear() method for some specified date. This method is used to fetch the year from a given Date object.



Example: It has applications such as getting the current year. It is used in websites to validate the age of the user.


<!DOCTYPE html>
<body style="text-align:center;">
        How to get the current 
        year in JavaScript?
    <button onclick="geeks()">
        click me
    <h4 id="myID"></h4>
        function geeks() {
            // Creating Date Object 
            var dateobj = new Date();
            // Year from above object 
            // is being fetched using getFullYear() 
            var dateObject = dateobj.getFullYear();
            // Printing current year 
                = "The Current Year is : " + dateObject;


  • Before Clicking on Button:

  • After clicking on Button:

Supported Browsers:

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Opera
  • Safari

My Personal Notes arrow_drop_up
Recommended Articles
Page :