Hello,
I am not a programmer, and I'm trying to use any of several JS scripts I've found on the net to display an HTML file's last-modified date in a Mac environment (Unix servers). The first script (see script 1 below) seems to display the
current system date, rather than the file's last-modified date. The other two scripts (see scripts 2 and 3 below) produce a blank line in both Safari and Firefox.
I've tried both embedding the JS in the HTML file and referencing it from an external file. There's no difference in the results. I'd prefer to reference an external JS file, so I can easily affect multiple pages in the small site I'm creating (4 pages).
The calling code is shown below:
Code:
<div id="footer">
<p><script type="text/JavaScript" src="../savedate.js"></script>
<noscript>
Updated June, 2008
</noscript>
<br>
Comments and corrections: <a href="[email_alias_here]?subject=Comment or correction on workflow page titled: ">contact the webmaster</a></p>
<!-- Footer end -->
</div>
Is it possible that the server does not have the module that supports the methods that the JS is using?
------------------------------
Script 1: appears to display current date
Code:
<!--
// Y2K READY-USE GetFullYear
// DAY Names Javascript is funny Starts the numbering with Zero this array translates to 0...6 to the days of the week
// REMEMBER Arrays have to be written all on ONE(1) line to work
var stampdays = new Array( "Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
// Month Names - Guess what this array does. 0..11 to the system clock month
var stampmonths = new Array( "January","February","March","April","May","June","July","August","September","October","November","December");
// GRABS the Date info from your System clock when your Browser reads enters the page.
var thedate = new Date();
//Gets the Translated Arrays written to the webpage for viewing. Remember you can use this for other things, too
document.write(stampdays[ thedate.getDay()] + ", " + stampmonths[ thedate.getMonth()] + " " + thedate.getDate() + ", " + thedate.getFullYear());
// -->
---------------
Script 2: produces blank line
Code:
<!-- Hide from old browsers
//
// format date as dd-mmm-yy
// example: 12-Jan-99
//
function date_ddmmmyy(date)
{
var d = date.getDate();
var m = date.getMonth() + 1;
var y = date.getYear();
// handle different year values
// returned by IE and NS in
// the year 2000.
if(y >= 2000)
{
y -= 2000;
}
if(y >= 100)
{
y -= 100;
}
// could use splitString() here
// but the following method is
// more compatible
var mmm =
( 1==m)?'Jan':( 2==m)?'Feb':(3==m)?'Mar':
( 4==m)?'Apr':( 5==m)?'May':(6==m)?'Jun':
( 7==m)?'Jul':( 8==m)?'Aug':(9==m)?'Sep':
(10==m)?'Oct':(11==m)?'Nov':'Dec';
return "" +
(d<10?"0"+d:d) + "-" +
mmm + "-" +
(y<10?"0"+y:y);
}
//
// get last modified date of the
// current document.
//
function date_lastmodified()
{
var lmd = document.lastModified;
var s = "Unknown";
var d1;
// check if we have a valid date
// before proceeding
if(0 != (d1=Date.parse(lmd)))
{
s = "" + date_ddmmmyy(new Date(d1));
}
return s;
}
//
// finally display the last modified date
// as DD-MMM-YY
//
document.write(
"Last updated: " +
date_lastmodified() );
// -->
------------------
Script 3: produces blank line
Code:
<!--
lastmod = document.lastModified // get string of last modified date
lastmoddate = Date.parse(lastmod) // convert modified string to date
if (lastmoddate == 0) { // unknown date (or January 1, 1970 GMT)
document.writeln("Last Modified: Unknown")
} else {
document.writeln("Last Modified: " + lastmod)
}
// -->