SEARCHES FAMILY TREES MAILING LISTS MESSAGE BOARDS

Display SSI Last_Modified in Local Time Format

A JavaScript Solution

When looking at a suitable way of keeping a "Last Modified" date/time stamp on each of my pages loaded to the Freepages server at Rootsweb.com, I decided to make use of the server's Last_Modified time-stamp which can be appended to each page.  This requires the following Server Side Includes (SSI) script to be added to the page:-

<!--#echo var="Last_Modified" -->

It is worth noting that these SSI commands are a subset of Perl language commands that are made available on the Rootsweb servers to enable the user to get some responses by using the #echo command, or as is more commonly used, the #include command which instructs the server to place a text file at a specific place on the page being served.  In the case of the "Last_Modified" variable that we are interested in, the server creates a time-stamp at the precise time the page was loaded to the server and appends this to the page each time it is downloaded.

In its simplest form - <!--#echo var="Last_Modified" --> the ouput of the servers time-stamp is in the following format:-

Wednesday, 17-Sep-2008 03:42:12 MDT

This means little to anyone viewing the page at some remote location on the planet, as they don't know that the Rootsweb servers are located at Provo, Utah in the United States of America, and that MDT stands for Mountain Daylight Time.  So it occured to me that it would be more use to see the time in a format easily recognised and meaningful to them.  The outcome is a small piece of JavaScript which makes use of the server's time-stamp in two ways; firstly by getting the server to configure the Date/Time output in a way that can be manipulated, and secondly by having the server separately provide a Time Zone stamp.  It is this Time Zone stamp that makes the script possible.

<object><noscript><span>Page Updated - <!--#echo var="Last_Modified" --></span></noscript></object>
<script type="text/javascript">
var sM = Date.parse('<!--#config timefmt="%B %d, %Y %H:%M:%S"--><!--#echo var="Last_Modified" -->');
var sZ = ('<!--#config timefmt="%Z"--><!--#echo var="Last_Modified" -->');
d = new Date();
var uZ = d.getTimezoneOffset() * 60000;
if(sZ == 'MDT') sO = 6 * 3600000;
else if(sZ == 'MST') sO = 7 * 3600000;
msecs = sM + sO + (uZ * -1);
uM = new Date(msecs);
document.write('Page Updated - ' + uM)
</script>

Simply, the script detects the server's time-stamp plus its Time Zone offset from GMT/UTC (Greenwich Mean Time / Universal Coordinated Time), then detects the user's computer time and its Time Zone offset from GMT/UTC and adjusts the output time in terms of the user's Local Time.  A more detailed description of how the script works can be found here.

Alert eyes will have noted the additional line above the script containing Page Updated text and a further "Last Modified" time-stamp within <span> tags.  This has been included so that if a user's JavaScript is off, the time-stamp will display the time as originally delivered by the server.  When JavaScript is enabled, the code nested within the <object><noscript> tags is not displayed.

In order for the above script to work it must be placed on each page, as it is the time-stamp generated by the server when the file was uploaded that is appended to the script when the page is called by a user.  One possible way of doing this, is to place the script in a <div> after the last paragraph on the page and before the container's closing </div>.  A possible coding example follows:-

<p>
Example text ..... "without any warranty of any kind, expressed or implied, or liability for its accuracy or omissions of any kind, nor for any loss or damage caused by a user's reliance on information obtained through this website, is given or implied".
</p>

<div style="margin-top:20px;font-family:verdana;font-size:18px;color:red;text-align:center;">


Highlight the complete script contained in the first block then Copy & Paste into the required location, then adjust the margin, font and color styles to suit.


</div>
</div><!--end Page Container -->
</body>
</html>

For those of using HTML 4.01 Transitional and who prefer using tables, the following sample code may assist you in placing the script:-

<table><tr><td>
<p>
Example text ..... "without any warranty of any kind, expressed or implied, or liability for its accuracy or omissions of any kind, nor for any loss or damage caused by a user's reliance on information obtained through this website, is given or implied".
</p>

<center>
<font color="#cc6699" size="2">


Highlight the complete script contained in the first block then Copy & Paste into the required location, then adjust the font and color styles to suit.


</font>
</center>
</td></tr></table>
</body>
</html>

Well that is all that needs to be done, and it is now necessary to load the page to the server in order for the time-stamp to show.  Once the page is on the server, open it and refresh (Ctrl +F5 or Ctr +R).  All things being equal, the new time-stamp will be displayed in terms of your Local Zone Time, and in a format determined by the browser in which the page is viewed.

<object><noscript><span>Page Updated - <!--#flastmod file="my_content.txt" --></span></noscript></object>
<script type="text/javascript">
var sM = Date.parse('<!--#config timefmt="%B %d, %Y %H:%M:%S"--><!--#flastmod file="my_content.txt" -->');
var sZ = ('<!--#config timefmt="%Z"--><!--#flastmod file="my_content.txt" -->');
d = new Date();
var uZ = d.getTimezoneOffset() * 60000;
if(sZ == 'MDT') sO = 6 * 3600000;
else if(sZ == 'MST') sO = 7 * 3600000;
msecs = sM + sO + (uZ * -1);
uM = new Date(msecs);
document.write('Page Updated - ' + uM)
</script>

Finally, the script in the box above is specifically modified to enable a .html page which has its content updated using a SSI .txt file to show the latest update time of that file. Other than using the #flastmod command, the operation of the script is identical to the first one.