|
| JAVASCRIPT setFullYear() METHOD
The setFullYear() method in javascript sets the year in 4 digits. Takes a compulsory year as a 4 digit number and an optional month and day parameter.
The general format is:
dateObject.setFullYear(year, month,[optional], day[optional]);
If you want to return the full date with the setFullYear() method, you will first have to create a new date object and then use the new date object with the setFullYear() method.
Example 1: With only the year supplied
<script type="text/javascript">
var dd=new Date(); // creates a new date object
dd.setFullYear(1989); // sets the date
document.write(dd); // outputs the date
</script>
The above will output:
Example 2: With all parameters supplied
<script type="text/javascript">
var dd=new Date(); // creates a new date object
dd.setFullYear(1999, 11, 26); // sets the date
document.write(dd); // outputs the date
</script>
The above will output:
With the above, remember that in javascript, January is month 0 through to December which is month 11.
See Also:
|
|