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.
<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>| Prev | Home | Next |
| Date.getDay() | Up | Date.getHours() |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. | ||