Date getFullYear() Method - Javascript Date

Javascript examples for Date:getFullYear

Description

The getFullYear() method returns the year in four digits for dates between year 1000 and 9999.

Parameters

None

Return Value:

A Number, representing the year of the specified date

The following code shows how to return the year:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {/*  ww  w.jav  a  2s.  co m*/
    var d = new Date("July 21, 2020 01:15:00");
    var n = d.getFullYear();
    document.getElementById("demo").innerHTML = n;
}
</script>

</body>
</html>

Related Tutorials