How to use getFullYear in JavaScript

In this article, I will explain use of getFullYear() Method in JavaScript data object.
  • 1627

JavaScript date getFullYear() method

  • getFullYear() of date object returns the year of the specified date.

  • In getFullYear() method, The returned value is an absolute number.

  • getFullYear() method returns a four-digit number

Syntax

Date.getFullYear()

Example

In the following example show to getFullYear() method returns current year.

<!DOCTYPE html>

<html>

<body>

<h3 style="color:Red">JavaScript getFullYear() Method Example</h3>

<p id="demo">Click for diaplay current year</p>

<button onclick="myFunction()">Click me</button>

<script type="text/javascript">

    function myFunction() {

        var d = new Date();

        var x = document.getElementById("demo");

        x.innerHTML = d.getFullYear();

        document.write("Current Year  is: " + d.getFullYear());

    }

</script>

</body>

</html>

Output1

getFullYear 1.jpg

Output2

getFullYear 2.jpg

You may also want to read these related articles here

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.