Previous Example-|-Next Example-|-Return to Chapter Listing

Example 11.2:
Using Date Object Methods


Click on the buttons to see the values held by the Date object we've created. The third button lets you set a value.

Click on the following button, then on the previous one to see the date change.



This is the script we used in the HEAD: <SCRIPT LANGUAGE="JAVASCRIPT"> <!-- TodaysDate = new Date() //--> </SCRIPT> Then these buttons in the BODY: <FORM> <INPUT TYPE=BUTTON VALUE="Get the hour held by TodaysDate" onclick="alert(TodaysDate.getHours())"><P> <INPUT TYPE=BUTTON VALUE="Get the year held by TodaysDate" onclick="alert(TodaysDate.getYear())"><P> <INPUT TYPE=BUTTON VALUE="Set the year held by TodaysDate to 99" onclick="TodaysDate.setYear(99)"><P> <INPUT TYPE=BUTTON VALUE="Get Greenwich Mean Time" onclick="alert(TodaysDate.toGMTString())"> </FORM>
Previous Example-|-Next Example-|-Return to Chapter Listing