setFullYear() method is used to set the full year for the specified date according to local time. In the given example, we have created a date object and specify date and time to it. Then we have used the method setFullYear() and specify 2008 as a parameter. When this html page is loaded, you will see that the year you have specified in the date object has been changed to 2008. You can also specify month and day value as a parameter.
Its syntax is:
year - a numeric value representing the year, e.g.
month - a numeric value representing the month (0 to 11).
day - a numeric value representing the day of the month (1 to 31). If you want to specify this parameter ,you have to specify the month..
Here is the code:
<h2>Use of setFullYear() Method</h2>
var date = new Date("Feb 5, 2009 01:35:00");
document.write("The new Date and Time is: <b>"+date+"</b>");
Output will be displayed as:
If you enjoyed this post then why not add us on Google+? Add us to your Circles
Liked it! Share this Tutorial