Javascript examples for Date:setFullYear
The setFullYear() method sets the year in four digits for dates between year 1000 and 9999.
date.setFullYear(year, month, day)
Parameter | Description |
---|---|
year | Required. A value representing the year, negative values are allowed |
month | Optional. An integer representing the month |
day | Optional. An integer representing the day of month |
month expected values are 0-11, but other values are allowed:
day expected values are 1-31, but other values are allowed:
A Number, representing the number of milliseconds between the date object and midnight January 1 1970
The following code shows how to Set the year to 2020:
<!DOCTYPE html> <html> <body> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {// ww w . j a va2 s . c o m var d = new Date(); d.setFullYear(d.getFullYear(), d.getMonth() - 6); document.getElementById("demo").innerHTML = d; } </script> </body> </html>