Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

How to get the current year using JavaScript ?

  • Last Updated : 11 Nov, 2021

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

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!