Home Javascript JavaScript method setFullYear()



JavaScript method setFullYear()
Posted on: June 11, 2009 at 12:00 AM
setFullYear() method is used to set the full year for the specified date according to local time.

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:

Download Source Code:

     

Related Tags for JavaScript method setFullYear():
cdatetimeobjectcreateifexampletoexamcieitpeiminmjspecmeobjxaxampsspcreatedathaimeivmpleaandssthavjepleplndo


More Tutorials from this section

Ask Questions?    Discuss: JavaScript method setFullYear()   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.