470,636 Members | 1,582 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,636 developers. It's quick & easy.

mtime?

Hello,

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?

Regards,

Oliver

Dec 7 '06 #1
4 1638

Oliver Block wrote:
Hello,

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?
alert(document.lastModified);

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

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. 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).

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) );
}

Further information can be found at: <insert current link>"

The styles and colours used in the linked page should be reviewed with
accessibility and legibility in mind.

--
Rob

Dec 7 '06 #2
RobG said the following on 12/6/2006 8:38 PM:
Oliver Block wrote:
>Hello,

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?

alert(document.lastModified);

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

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.
It doesn't even come close. And, the Subject is too specific as it
limits itself to the Last Modified when you format Last Modified the
same way you would format any other Date.
The link appears to point to the wrong reference,
I think the best reference, for an FAQ and a newbie reading the FAQ,
doesn't exist in that page.
I need to scroll down several pages (6 "page downs") to find the
bit on lastModified. The use of a small, italic font on a bright yellow
background makes reading the page very difficult.
Indeed it does.
The text in the box with a green/blue background is nearly
illegible on my monitor (17" at 1280x1024, default font 16pt).
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) );
}

Further information can be found at: <insert current link>"
<URL: http://www.javascripttoolbox.com/lib/date/>
<g>
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Dec 7 '06 #3

Randy Webb wrote:
RobG said the following on 12/6/2006 8:38 PM:
[...]
Further information can be found at: ...

<URL: http://www.javascripttoolbox.com/lib/date/>
<g>
I'm not a fan of suggesting any particular library unless it stands out
as a paragon or seminal work, but what the heck... :-)
--
Rob

Dec 7 '06 #4
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.
Dec 7 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

699 posts views Thread by mike420 | last post: by
4 posts views Thread by Ishwar Rattan | last post: by
5 posts views Thread by Erwin Kloibhofer | last post: by
5 posts views Thread by Peter Erickson | last post: by
5 posts views Thread by Skip | last post: by
9 posts views Thread by Wolfgang Draxinger | last post: by
1 post views Thread by Korara | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.