Date.getFullYear() (Method)

Returns the full year for a date/time.

Availability:

ECMAScript edition - 2
JavaScript - 1.3
JScript - 3.0
Internet Explorer - 4.0
Netscape - 4.0
Property/method value type:Number primitive
JavaScript syntax:-myDate.getFullYear()

The full year number of the date value in the receiving object is returned as a four digit value. This is much preferred to the getYear() method which suffers from Y2K ambiguities and is now deprecated in favor of this method.

The year number is a local time value.

Example code:

   <HTML>
   <HEAD></HEAD>
   <BODY>
   <SCRIPT>
   // Calculate which century from the year number
   myDate = new Date();
   myCentury = 1 + myDate.getFullYear()/100;
   switch (myCentury % 10)
   {
   case 1 : mySuffix = "st";
   break;
   
   case 2 : mySuffix = "nd";
   break;
   
   case 3 : mySuffix = "rd";
   break;
   
   default : mySuffix = "th";
   break;
   
   }
   document.write(myCentury + mySuffix + " century");
   </SCRIPT>
   </BODY>
   </HTML>

See also:Date.getYear(), Date.prototype, Date.setFullYear(), Date.setUTCFullYear(), Date.setYear()

Cross-references:

ECMA 262 edition 2 - section - 15.9.5.6

ECMA 262 edition 3 - section - 15.9.5.10