In comp.lang.javascript message
<11*********************@16g2000cwy.googlegroups.c om>, Wed, 6 Dec 2006
17:38:22, RobG <rg***@iinet.net.auwrote:
>
Oliver Block wrote:
>does anybody know, if there is a possibility to get the date and time of the
last modification of a document (file) from withing JavaScript?
Note : the question does not definitely assert that the document whose
date is wanted is the document running the javascript. I could want my
Index page to show the dates of all the pages that it points to. AFAIK,
javascript in a Web page cannot obtain the date of any other page,
except by loading the other page into a window and addressing its
lastModified [1]. But Javascript in WSH should be able to get such
stuff directly, for local files.
[1] testing in WinXP sp2 IE6 js-quick.htm,
Q = window.open("js-alarm.htm", "fred")
Q.document.lastModified
shows 11/26/2006 18:14:28 - FFF, no GMT, else OK.
alert(document.lastModified);
In some browsers and countries, that will show a wrong, but plausible,
date for 11 days out of every month, and a ludicrous one for every other
day but one. In some browsers, the century has been undefined. I've
only heard of one case where the lastModified date string includes an
indication of the offset from GMT.
>There is an FAQ entry:
<URL: http://www.jibbering.com/faq/#FAQ4_30 >
<FAQENTRY>
The entry:
" 4.30 How do I format Last Modified date with javascript
There "format" is not interpreted with the appropriate emphasis; the
section was not intended to refer to the presentation of the Date Object
as a string, but to the correct interpretation of lastModified itself.
Change "format" to "handle".
Apparently, new Date() reads it correctly, though problems can occur
if the browser returns only two digits for the year. In particular,
time zone, field order and separators may vary. It is also reliant on
the server's clock having been correctly set at the time of upload. See
the URL below."
is cryptic and doesn't answer the question. The link appears to point
to the wrong reference, I need to scroll down several pages (6 "page
downs") to find the bit on lastModified.
It points to the <H2heading "Last Modified", where the topic begins;
that is as intended.
The use of a small, italic
font on a bright yellow background makes reading the page very
difficult. The text in the box with a green/blue background is nearly
illegible on my monitor (17" at 1280x1024, default font 16pt).
ISTM that the font size there is about what the newFAQ gives me, but the
face is more legible for me (it will be "monospace"). Black-on-yellow
is agreed to give a clear distinction by most ordinary UK wasps.
Monitors vary; here I see it as a full, but not bright, yellow, and in
the Library ISTR it as being rather paler. It is the colour called
"yellow"; #FF0000.
>A suggested alternative wording is:
"The document.lastModified property can be formatted either by string
manipulation or by creating a Date object and using it to generate a
formatted string, e.g.
if (typeof document.lastModified == 'string') {
alert( new Date(document.lastModified) );
}
Are there any systems where lastModified exists and is not a String? If
not, maybe if (!document.lastModified) ? Are there any systems where
it does not exist?
My belief is that, apart from the missing GMT offset and possible
century error, all browsers will, using your code, get the right year,
month, and day; perhaps all recent ones will get the right century.
The century question is trivial to handle; all pages are read (if at
all) after they've been written, and few authors yet expect their pages
to be in use after 2099. But showing "Last update : 1906" or "Last
update : Fri 07 Dec 06" is unprofessional.
The data is transmitted in required explicit GMT (from my servers, and
from all compliant ones) but I don't know how to tell, in javascript,
whether the date in lastModified is copied as GMT or converted to local.
ECMA could, for the future, usefully add document.lastModMSec as if
obtained by +new Date(<Last-Modified RFC2616 Header>). It would be
unambiguous and would load efficiently into a Date Object. Or, of
course, add document.lastModObj, a Date Object.
--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6.
Web <URL:http://www.merlyn.demon.co.uk/- w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/- see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.