JavaScript method setFullYear()
This section illustrates you the use of JavaScript method setFullYear()
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:
dateObject.setFullYear(year,month,day) |
year - a numeric value representing the year, e.g.
2008.
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:
<html> <h2>Use of setFullYear() Method</h2> <script type="text/javascript"> var date = new Date("Feb 5, 2009 01:35:00"); date.setFullYear(2008); document.write("The new Date and Time is: <b>"+date+"</b>"); </script> </html> |
Output will be displayed as: