|
| JAVASCRIPT getFullYear() METHOD
The getFullYear() method in javascript returns the year in the format of 4 digits.
The general format is:
dateObject.getFullYear();
If you want to return the year as a 4 digit number with getFullYear() method, you will first have to create a new date object and then use the new date object with the getFullYear() method.
Example 1: Using getFullYear() for current year:
<script type="text/javascript">
var yyyy=new Date(); // creates a new date object
yyyy=yyyy.getFullYear(); // returns the year in a 4 digit format
document.write(yyyy); // outputs the year
</script>
The above will output:
Example 2: Using getFullYear() to get the year of a specified date:
<script type="text/javascript">
var yyyy=new Date("January 16, 1999"); // creates a new date object
yyyy=yyyy.getFullYear(); // returns the year in a 4 digit format
document.write(yyyy); // outputs the year
</script>
The above will output:
See Also:
|
|