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