Contents Home Page Previous Page Next Page

Document Last Modified

You will have noticed the "Page last modified..." line at the foot of almost every page on this site. That is a pretty complicated code to display the date the document was last saved in the format I prefer. If you want to grab that script, view the source code. Here is a much simpler version:

<script language="JavaScript">
<!--
   document.write("Page last modified " + document.lastModified)
// -->
</script>

This appears on the Web page as:


Here is another way, a good bit longer than the example above, but shorter than the one I use on my pages:

<script language="JavaScript">
<!--
     function initArray() {
     this.length = initArray.arguments.length
     for (var i = 0; i < this.length; i++)
         this[i+1] = initArray.arguments[i]
}

var MonthOfYearArray = new initArray("January","February","March","April",
                                     "May","June","July","August",
                                     "September","October","November","December");

var LastModifiedDate = new Date(document.lastModified);

document.write("Page last modified ");
document.write(MonthOfYearArray[(LastModifiedDate.getMonth()+1)]," ");
document.write(LastModifiedDate.getDate(),",",(LastModifiedDate.getYear()+1900));
//-->
</script>

This appears as:


Note that some servers do not return the lastModified details so this script will not always work. It may work fine on your hard disk, but not when uploaded. One culprit I know of in particular is Compuserve's Ourworld.