473,543 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

document.lastMo dified 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(doc ument.lastModif ied) != 0) {
var modiDate = new Date(document.l astModified); var modiYear =
modiDate.getYea r();
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.getMon th()] + " ");
document.write( modiDate.getDat e() + ", " + modiYear); }
//

I call it like this:

<SCRIPT SRC="datemod.js " LANGUAGE="JavaS cript"></SCRIPT>

--John
Jul 20 '05 #1
1 4696
JRS: In article <pan.2004.01.17 .23.21.59.59425 3@remove-this-nospam-
part.fas.harvar d.edu>, seen in news:comp.lang. javascript, John Norvell
<no*****@remo ve-this-nospam-part.fas.harvar d.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(doc ument.lastModif ied) != 0) {
var modiDate = new Date(document.l astModified); var modiYear =
modiDate.getYea r();
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.getMon th()] + " ");
document.write( modiDate.getDat e() + ", " + 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.demo n.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 unsatisfactoril y.
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.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.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
2567
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 of the most current version of the program avialable online. I want the program to be able to "see" if the program has changed without having a...
12
3219
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
1158
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 case it is returning the current date and time. It only does this when it is on the webserver. the code is: <script type="text/javascript"><!--...
2
1821
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 IE etc it shows the "current" date, but not the file's last mod date!!! I've searched the net and I've seen many posts with simular issues, but I...
12
10134
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 scrollbar, you get the height of the entire document, screwing up any chance of centering a window in the browser using these values. Is there a...
15
2278
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 in my code, as it does not seem to work? I am actually trying to learn what parts of the code do what and why, so if anyone can take the time to...
2
1351
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. I have some php includes in the index files. When I change the php file to htm file the lastModified function works correctly. Any help?
6
7673
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 using an XPathNodeIterator? Or should I be using something else? In the sample that follows: 1. Grab all "Page" nodes. 2. Loop through all the...
0
7412
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7594
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7746
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
5889
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5285
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4899
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3394
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1830
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
648
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.