JavaScript for Displaying Date Document Last Modified

It is easy to display the date and time that the current document was last modified in JavaScript. You simple need to embed the following into your HTML:

<script type="text/javascript">document.write (document.lastModified);</script>

Unfortunately, how this is displayed depends on the browser rendering the page. e.g.

Browser Display Format
Opera Sat, 14 Aug 2004 19:39:36 GMT
Mozilla Saturday, August 14, 2004 19:39:36
Internet Explorer 08/14/2004 19:39:36
Netscape Saturday 14 August 2004 19:39:36

This JavaScript routine displays the date in a consistent format, either with or without the time fields as follows:

Calling Sequence Result
<script type="text/javascript">writeDateModified (false);</script>
<script type="text/javascript">writeDateModified (true);</script>

Download compressed JavaScript file (1.18 KB)