How to use setFullYear in JavaScript
In this article, I will explain use of setFullYear() method in JavaScript date object.
JavaScript setFullYear() method
Syntax
Date.setFullYear(yearValue,monthValue,dayValue)
|
- yearValue : A four-digit value representation the year. An integer specifying the numeric value of the year, for example, 2012.
- monthValue : monthValue is the optional parameter. An integer between 0 and 11 representing the months January through December.
- dayValue : dayValue is the optional parameter. An integer between 1 and 31 representing the day of the month. If you given the dayValue parameter, you must also given the monthValue.
Example
In the following example show to setFullYear() method set the date to six months ago.
<!DOCTYPE html>
<html>
<body>
<h3 style="color:Teal ">JavaScript setFullYear() Method Example</h3>
<p id="demo">Click for display the date six months ago.</p>
<button onclick="myFunction()">Click On</button>
<script type="text/javascript">
function myFunction() {
var d = new Date();
d.setFullYear(d.getFullYear(), d.getMonth() - 6);
var x = document.getElementById("demo");
x.innerHTML ="Six Months Ago Date is : "+ d;
}
</script>
</body>
</html>
|
Output1

Output2

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