|
| JAVASCRIPT setMonth() METHOD
The setMonth() method in javascript returns the date and time by setting the month. Takes the compulsory month argument as number from 0 to 11 (0 for January, 1 for February, etc), and an optional day argument as a number from 1 to 31.
The general format is:
dateObject.setMonth(month, day,[optional]);
If you want to return the full date and time with the setMonth() method, you will first have to create a new date object and then use the new date object with the setMonth() method.
Example 1: With only the month supplied
<script type="text/javascript">
var dd=new Date(); // creates a new date object
dd.setMonth(6); // sets the date
document.write(dd); // outputs the date
</script>
The above will output:
Example 2: With month and day specified
<script type="text/javascript">
var dd=new Date(); // creates a new date object
dd.setMonth(6, 25); // sets the date
document.write(dd); // outputs the date
</script>
The above will output:
See Also:
|
|