Skip to content
Related Articles
Open in App
Not now

Related Articles

How to get the current year using JavaScript ?

Improve Article
Save Article
  • Last Updated : 11 Nov, 2021
Improve Article
Save Article

In this article, we will know how to get the current year using the build-in method in Javascript. The purpose is to get the current year by using JavaScript getFullYear() method that will return the full year in 4-digit format for some specified date. This method is used to fetch the year from a given Date object.



Parameter: This function does not accept any parameters.

Return Values: It returns the year for the given date.

Example: This example describes getting the current year. Generally, it is used to validate the input year in the 4-digit format on the website.


<!DOCTYPE html>
<body style="text-align:center;">
        How to get the current 
        year in JavaScript?
    <button onclick="geeks()"> click me </button>
    <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 
        document.getElementById("myID").innerHTML = 
        "The Current Year is : " + dateObject;


 getting the current year

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!