473,394 Members | 1,709 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

document.lastModified returns current date!

I just noticed that recently the javascript I was using to format and
display the last modified date of my web page is always reporting the
current date instead. It used to work fine. This is true both on the
university web server on which the page is hosted and the local mirror I
keep on my desktop (SuSE 8.2 Linux). It is a new university, but my
desktop filesystem is the same as before. I can see with "ls -l" that the
modified date of the file has not been changed. I am really befuddled! I
have tried several different scripts now, and they all show the same
behavior. Any clues about this?

Here's what I've been using:

// Formatted last-modified date
if (Date.parse(document.lastModified) != 0) {
var modiDate = new Date(document.lastModified); var modiYear =
modiDate.getYear();
modiYear = (modiYear < 2000) ? modiYear + 1900 : modiYear; var
monthName = new Array("January", "February", "March", "April",
"May",
"June", "July", "August", "September", "October", "November",
"December");
document.write(monthName[modiDate.getMonth()] + " ");
document.write(modiDate.getDate() + ", " + modiYear); }
//

I call it like this:

<SCRIPT SRC="datemod.js" LANGUAGE="JavaScript"></SCRIPT>

--John
Jul 20 '05 #1
1 4677
JRS: In article <pan.2004.01.17.23.21.59.594253@remove-this-nospam-
part.fas.harvard.edu>, seen in news:comp.lang.javascript, John Norvell
<no*****@remove-this-nospam-part.fas.harvard.edu> posted at Sat, 17 Jan
2004 18:22:00 :-
I just noticed that recently the javascript I was using to format and
display the last modified date of my web page is always reporting the
current date instead. It used to work fine. This is true both on the
university web server on which the page is hosted and the local mirror I
keep on my desktop (SuSE 8.2 Linux). It is a new university,
?? Even by Oxbridge, Harvard is no longer considered really "new" ??
but my
desktop filesystem is the same as before. I can see with "ls -l" that the
modified date of the file has not been changed. I am really befuddled! I
have tried several different scripts now, and they all show the same
behavior. Any clues about this?
Perhaps you meant "the University's server is new"?

Here's what I've been using:

// Formatted last-modified date
if (Date.parse(document.lastModified) != 0) {
var modiDate = new Date(document.lastModified); var modiYear =
modiDate.getYear();
modiYear = (modiYear < 2000) ? modiYear + 1900 : modiYear; var
monthName = new Array("January", "February", "March", "April",
"May",
"June", "July", "August", "September", "October", "November",
"December");
document.write(monthName[modiDate.getMonth()] + " ");
document.write(modiDate.getDate() + ", " + modiYear); }
//
Since that gives date-like but unsatisfactory results, look directly at
lastModified. If that shows "today", you cannot hope to get a desired
earlier modification date by correcting the code shown.

If you think your Subject line is an accurate representation of the
situation, why did you think it necessary to give the code that
interprets it?
That code, on a test page dated 2003-12-30, reports "December 30, 1903";
your Y2k logic is inadequate, but the interpreting code is presumably
NOT responsible for giving you "today".

For that page, lastModified shows me 12/30/03 20:20:54, and getYear
gives 3, in my MSIE 4. Note that, as well as missing 20, the date field
order is incorrect.
You should have read the c.l.j FAQ, which gives relevant advice; you
should read <URL:http://www.merlyn.demon.co.uk/js-date3.htm#lM>.
It seems evident that either the server is returning the current date in
the Last-Modified line of the HTTP header, in which case reconfigure the
server and/or its operator; or that it is returning no such line, in
which case the fault is on your machine, in interpreting the absence of
data unsatisfactorily.
Note that L-M is transmitted in GMT & marked as such, or AIUI should be;
d.lM is likely to use the same figures, without GMT, for at least some
browsers; Date.parse assumes local time by default. The zone of origin
is not known, so the author's upload date cannot be known for a WWW
page. The coder can cause either the GMT date or the reader's date to
be shown; but should indicate clearly which is the case.

The only sensible move is for the author to write the date, in an
internationally unambiguous manner, in the HTML; it should then be
assumed to be author's local civil date, unless otherwise specified.
--John


FYI:
A correct SigSep is a line containing only the three characters '-- '.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: x | last post by:
Here's my problem... I have a file on many many users remote machines (with different OS's, etc) and I want to have my program test the date that the file that they are using, against the date...
12
by: Bart | last post by:
Hallo, I'm have a problem with the following script: function wr(s) { //Just got tired of writing document.write, //so I created a shorthand version document.write(s);
12
by: *.* | last post by:
Hey- I seem to be having a problem with the document.lastModified property. The way it is suppose to work is that it returns the date and time at which the document was last modified. IN my...
2
by: Kam Bansal | last post by:
Hi all, We're using Apache 1.3 (I know, I know, there's a newer version...) and it seems that the document.lastModified does not return the correct date. On Netscape it shows 01/01/1970 and on...
12
by: Kepler | last post by:
How do you get the height of the client browser in IE? Both document.body.clientHeight and document.body.offsetHeight return the height of the document. If the page is long and there's a vertical...
15
by: Cerebral Believer | last post by:
Hi all, I am a newbie to JavaScript and am just trying to get a script going that will write the ful date and time to each webpage as it is viewed. Can anyone point out what mistakes there are...
2
by: dbahlmann | last post by:
Hi, I'm using document.lastModified function to return my document last mod date. The function returns 1-Jan-1970. The problem seems to be that the file name is index.php instead of index.html....
6
by: Kindler Chase | last post by:
I'm trying to iterate through a set of nodes and then edit/delete specific attributes using XPathNodeIterator. Adding attributes is no problem. My first question is how do I delete an attribute...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.