Last Updated Date and Time

R

runsrealfast

I have a web page that is a help page for users to get information on.
It has links to documents that contain the information that they might
need. These documents can get updated on an irregular basis with out
me (being the owner of the web page) knowing.

My questions is this, is there away using JavaScript to get the last
modified date and time for these files? I would then like to output
them to the web page so users can see the last time the document was
updated.

Thanks

John
 
S

Steve Swift

My questions is this, is there away using JavaScript to get the last
modified date and time for these files?

This is what I use:

<SCRIPT LANGUAGE="JavaScript">
function Initialize()
{ this.length = Initialize.arguments.length
for ( var i = 0; i < this.length; i++ ) this[ i + 1 ] =
Initialize.arguments[ i ]
}

var DayOfWeek = new Initialize("Sunday", "Monday", "Tuesday",
"Wednesday", "Thursday", "Friday", "Saturday" );
var MonthName = new Initialize("January", "February", "March", "April",
"May", "June", "July", "August", "September", "October", "November",
"December");
var LastModifiedDate = new Date(document.lastModified);

document.write("<SMALL>This site was last updated ");
document.write(DayOfWeek[(LastModifiedDate.getDay() + 1 )] ,", ");
document.write(MonthName[(LastModifiedDate.getMonth() + 1)] ," ");
year=LastModifiedDate.getYear();
if (year<100) year+=100;
if (year<1000) year+=1900;
document.write( LastModifiedDate.getDate() ,", " ,( year ) );
hours= LastModifiedDate.getHours();
document.write( " at ", ((hours < 10) ? "0" : "") + hours )
minutes= LastModifiedDate.getMinutes();
document.write( ((minutes < 10) ? ":0" : ":") + minutes );
document.write(" by");
</SCRIPT>
 
R

runsrealfast

My questions is this, is there away using JavaScript to get the last
modified date and time for these files?

This is what I use:

<SCRIPT LANGUAGE="JavaScript">
function Initialize()
{ this.length = Initialize.arguments.length
for ( var i = 0; i < this.length; i++ ) this[ i + 1 ] =
Initialize.arguments[ i ]
}

var DayOfWeek = new Initialize("Sunday", "Monday", "Tuesday",
"Wednesday", "Thursday", "Friday", "Saturday" );
var MonthName = new Initialize("January", "February", "March", "April",
"May", "June", "July", "August", "September", "October", "November",
"December");
var LastModifiedDate = new Date(document.lastModified);

document.write("<SMALL>This site was last updated ");
document.write(DayOfWeek[(LastModifiedDate.getDay() + 1 )] ,", ");
document.write(MonthName[(LastModifiedDate.getMonth() + 1)] ," ");
year=LastModifiedDate.getYear();
if (year<100) year+=100;
if (year<1000) year+=1900;
document.write( LastModifiedDate.getDate() ,", " ,( year ) );
hours= LastModifiedDate.getHours();
document.write( " at ", ((hours < 10) ? "0" : "") + hours )
minutes= LastModifiedDate.getMinutes();
document.write( ((minutes < 10) ? ":0" : ":") + minutes );
document.write(" by");
</SCRIPT>


How/where do I specify what file to get the last update from. Wont
this only show the web page (.html file)?

John
 
T

Thomas 'PointedEars' Lahn

Steve said:
My questions is this, is there away using JavaScript to get the last
modified date and time for these files?

This is what I use:

<SCRIPT LANGUAGE="JavaScript">
http://validator.w3.org/

function Initialize()
{ this.length = Initialize.arguments.length
for ( var i = 0; i < this.length; i++ ) this[ i + 1 ] =
Initialize.arguments[ i ]
}

var DayOfWeek = new Initialize("Sunday", "Monday", "Tuesday",
"Wednesday", "Thursday", "Friday", "Saturday" );

Have you ever heard of Array objects?

Since JavaScript 1.1 (NN 3.0), JScript 2.0, ECMAScript 1:

var dayOfWeek = new Array("Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday");

Since JavaScript 1.3 (NN 4.01), JScript 2.0 (IIS 3.0, Win NT 4.0, IE 4.0),
ECMAScript 3:

var dayOfWeek = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday",
"Friday", "Saturday"];
[...]
var LastModifiedDate = new Date(document.lastModified);
http://jibbering.com/faq/#FAQ4_30

document.write("<SMALL>This site was last updated ");

Unfinished elements should not be written, this is error-prone.
document.write(DayOfWeek[(LastModifiedDate.getDay() + 1 )] ,", ");
document.write(MonthName[(LastModifiedDate.getMonth() + 1)] ," ");

Consecutive calls of document.write() are inefficient and sometimes
error-prone. That method is standardized to accept only one argument;
everything else is a proprietary extension that should not be relied on.

The parantheses around the index argument serve no reasonable purpose.

With an Array object as data source, there is no need to increase the
index argument twice.

document.write([
dayOfWeek[lastModifiedDate.getDay()], ", ",
monthName[lastModifiedDate.getMonth()], ", ",
...
].join(""));
year=LastModifiedDate.getYear();
if (year<100) year+=100;
if (year<1000) year+=1900;

Error-prone. Use Date::getFullYear() instead, and a better fallback than this.

http://jibbering.com/faq/#FAQ4_30


PointedEars
 
T

Thomas 'PointedEars' Lahn

runsrealfast said:
My questions is this, is there away using JavaScript to get the last
modified date and time for these files?
This is what I use:
[document.lastModified interpreted]

How/where do I specify what file to get the last update from. Wont
this only show the web page (.html file)?

It will only evaluate the Last-Modified HTTP header served with the current
(X)HTML resource; that is not necessarily the file modification time. You
should employ a better algorithm to parse the Last-Modified HTTP header for
your other resources; obviously, you would need (X)XMLHttpRequest() for that
or a bunch of iframes, and proxies could still interfere.

You should do that server-side instead.


PointedEars
 
S

Steve Swift

Have you ever heard of Array objects?

Well, other than "Array" and "objects", yes. :)

I picked up that script roughly 10 years ago (the maths done on the year
indicates that it comes from before 2000 at the very least) and I've had
no reason to change it.

I did notice in passing that I don't close the <SMALL> tag, but even
that hasn't affected me as I always use it right at the bottom of my pages.
 
S

Steve Swift

How/where do I specify what file to get the last update from. Wont
this only show the web page (.html file)?

Yes, it's designed to show when "this" document last changed. I wouldn't
have a clue how to reference the last changed date of some other
document. I'd do that sort of thing with a CGI script.
 
R

runsrealfast

runsrealfast said:
My questions is this, is there away using JavaScript to get the last
modified date and time for these files?
This is what I use:
[document.lastModified interpreted]
How/where do I specify what file to get the last update from. Wont
this only show the web page (.html file)?

It will only evaluate the Last-Modified HTTP header served with the current
(X)HTML resource; that is not necessarily the file modification time. You
should employ a better algorithm to parse the Last-Modified HTTP header for
your other resources; obviously, you would need (X)XMLHttpRequest() for that
or a bunch of iframes, and proxies could still interfere.

You should do that server-side instead.

PointedEars


Maybe PHP would be better for this than javascript?

John
 
E

Evertjan.

Thomas 'PointedEars' Lahn wrote on 16 aug 2007 in comp.lang.javascript:
var dayOfWeek = new Array("Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday");

Just for variaton:

function dayOfWeek(x) {
return 'Sun/Mon/Tues/Wednes/Thurs/Fri/Satur'.split('/')[x]+'day';
};
 
T

Thomas 'PointedEars' Lahn

Steve said:
Well, other than "Array" and "objects", yes. :)

I picked up that script roughly 10 years ago (the maths done on the year
indicates that it comes from before 2000 at the very least) and I've had
no reason to change it.

Array objects and Array::join() were already supported roughly 10 years ago
(NN 3.0 dates back 1996-08, IE 4.0 dates back 1997-10). And I would never
post an old script without reviewing/refactoring it first, or even
indicating that it probably needs work.
I did notice in passing that I don't close the <SMALL> tag, but even
that hasn't affected me as I always use it right at the bottom of my pages.

Voodoo programming pricks you in the foot when you expect it least.


PointedEars
 
T

Thomas 'PointedEars' Lahn

runsrealfast said:
runsrealfast said:
[document.lastModified interpreted]
How/where do I specify what file to get the last update from. Wont
this only show the web page (.html file)?
It will only evaluate the Last-Modified HTTP header served with the current
(X)HTML resource; that is not necessarily the file modification time. You
should employ a better algorithm to parse the Last-Modified HTTP header for
your other resources; obviously, you would need (X)XMLHttpRequest() for that
or a bunch of iframes, and proxies could still interfere.

You should do that server-side instead.
[...]

Please trim your quotes, and don't quote signatures unless you are referring
to them directly.
Maybe PHP would be better for this than javascript?

You may employ any programming language that can be used server-side, even
JavaScript (or, more likely, JScript in ASP).

However, PHP would be (and is, in fact) my first choice here:

http://php.net/filemtime


HTH

PointedEars
 
S

Steve Swift

And I would never post an old script without reviewing/refactoring it
first, or even indicating that it probably needs work.

Ah, there's the important word, "work". I work in a commercial
environment where you have to cost-justify work before doing it.

The business case to "Fix this code that has never been known to fail,
because it would then be better" is a battle that you never win.
 
D

Dr J R Stockton

Thu said:
This is what I use:

<SCRIPT LANGUAGE="JavaScript">
---- Deprecated -----
function Initialize()
{ this.length = Initialize.arguments.length
for ( var i = 0; i < this.length; i++ ) this[ i + 1 ] =
Initialize.arguments[ i ]
}

But where did you get the code from? One can more easily use array
literals, and would not then need to use +1 later.

var DayOfWeek = new Initialize("Sunday", "Monday", "Tuesday",
"Wednesday", "Thursday", "Friday", "Saturday" );
var MonthName = new Initialize("January", "February", "March", "April",
"May", "June", "July", "August", "September", "October", "November",
"December");
var LastModifiedDate = new Date(document.lastModified);

Refers to the current Web page (and not, AFAIK, to included files, which
may be older or newer). The date and time are transmitted as GMT, but
some browsers have treated them as local.
document.write("<SMALL>This site was last updated ");
document.write(DayOfWeek[(LastModifiedDate.getDay() + 1 )] ,", ");
document.write(MonthName[(LastModifiedDate.getMonth() + 1)] ," ");
year=LastModifiedDate.getYear();

Nowadays, getFullYear should be safe.
if (year<100) year+=100;
if (year<1000) year+=1900;

Provided that you do not upload the page before the Year 2000, and can
ignore Y2.1K, year = 2000 + year%100 is simpler, if you don't
trust getFullYear. OTOH, getFY can be synthesised.
document.write( LastModifiedDate.getDate() ,", " ,( year ) );
hours= LastModifiedDate.getHours();
document.write( " at ", ((hours < 10) ? "0" : "") + hours )
minutes= LastModifiedDate.getMinutes();
document.write( ((minutes < 10) ? ":0" : ":") + minutes );

Should have an indication of whether that is author's time, GMT, or
reader's time.
document.write(" by");
</SCRIPT>


It's a good idea to read the newsgroup c.l.j and its FAQ. See below.
 
T

Thomas 'PointedEars' Lahn

Steve said:
Ah, there's the important word, "work". I work in a commercial
environment where you have to cost-justify work before doing it.

Oh, me too. But this newsgroup is part of the *private* life. You don't
have to post a script once you see the question (it is not a real-time
discussion anyway), and you don't have to post it if you know it probably
needs work. So I would consider it polite behavior towards the potential
reader (who is probably not able to see the issues at once) at least to
mention that it is an old snippet that should not be copypasted as is.
The business case to "Fix this code that has never been known to fail,
because it would then be better" is a battle that you never win.

Granted, that seldom happens. However, doing at least *some* QA in the
first place helps to avoid that situation.


Please provide proper attribution next time.


Regards,

PointedEars
 
R

runsrealfast

Thomas 'PointedEars' Lahn said the following on 8/16/2007 1:54 PM:


runsrealfast said:
[...] Thomas 'PointedEars' Lahn [...] wrote:
runsrealfast wrote:
[document.lastModified interpreted]
How/where do I specify what file to get the last update from. Wont
this only show the web page (.html file)?
It will only evaluate the Last-Modified HTTP header served with the current
(X)HTML resource; that is not necessarily the file modification time. You
should employ a better algorithm to parse the Last-Modified HTTP header for
your other resources; obviously, you would need (X)XMLHttpRequest() for that
or a bunch of iframes, and proxies could still interfere.
You should do that server-side instead.
[...]
Please trim your quotes, and don't quote signatures unless you are referring
to them directly.

Correct your broken signature and then you can complain about people
quoting it. Or, are you back to your "It isn't my signature" defense?

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ -http://jibbering.com/faq/index.html
Javascript Best Practices -http://www.JavascriptToolbox.com/bestpractices/



Damn how many internet police officers are in this NG?
 
J

John Hosking

Joe said:
Out of curiosity, what is broken about his signature?

A signature is delimited by a "sig separator" consisting of two dashes
and a space, alone on a line. That is:

dash-dash-space-linefeed

Just like mine below, and like yours, and like Randy Webb's. "Pointed
Ears" hasn't seemed to catch on yet, so no newsreader can display his
sig in a different color (my TB does it in gray) and no newsreader can
automatically trim his sig when someone replies to one of his posts.
 
S

Steve Swift

But where did you get the code from?

It comes from the dim and distant past, like me.
 
T

Thomas 'PointedEars' Lahn

John Hosking said:
A signature is delimited by a "sig separator" consisting of two dashes
and a space, alone on a line. That is:

dash-dash-space-linefeed

Just like mine below, and like yours, and like Randy Webb's. "Pointed
Ears"

My nickname is spelled without a space character, thank you.
hasn't seemed to catch on yet, so no newsreader can display his
sig in a different color (my TB does it in gray) and no newsreader can
automatically trim his sig when someone replies to one of his posts.

Cheap talk about imagined recommendations (the meaning of .sig has changed
since the early days of Usenet, see the many private signature archives that
do not contain any contact information in the four lines) from someone who
is not even able to provide the courtesy of a sender address that complies
to RFC1036 and RFC2822, one that not violates RFC2606, and so can be replied
to. FOAD.


PointedEars
 
D

Dr J R Stockton

Thu said:
I picked up that script roughly 10 years ago (the maths done on the
year indicates that it comes from before 2000 at the very least) and
I've had no reason to change it.

Ancient code should never be given in response to a current question, at
least until sufficient time has been allowed (which means at least a
day) for something better to appear, unless one is satisfied that
current code cannot be better; and it should be marked as ancient.
 
R

runsrealfast

Just thought I would show this email that MR pointedears sent me:

Hello,

you wrote in comp.lang.javascript:
Thomas 'PointedEars' Lahn said the following on 8/16/2007 1:54 PM:
runsrealfast wrote:
[...] Thomas 'PointedEars' Lahn [...] wrote:
runsrealfast wrote:
[document.lastModified interpreted]
How/where do I specify what file to get the last update from. Wont
this only show the web page (.html file)?
It will only evaluate the Last-Modified HTTP header served with the current
(X)HTML resource; that is not necessarily the file modification time. You
should employ a better algorithm to parse the Last-Modified HTTP header for
your other resources; obviously, you would need (X)XMLHttpRequest() for that
or a bunch of iframes, and proxies could still interfere.
You should do that server-side instead.
[...]
Please trim your quotes, and don't quote signatures unless you are referring
to them directly.
[quoted signature again]

Damn how many internet police officers are in this NG?

None, well maybe one or two. There are always people who don't have
anything substantial to say. That would not include me, though. From
me,
you have received a helpful reply (or so I hope), and in addition to
that a
polite request (repeatedly) to follow established and therefore
expected
posting guidelines. For the good of the group and, last but not
least, for
your own good.

Because your ongoing ignorance of that request marks you as being
ignorant
towards the wishes of the community of the newsgroup, and the Usenet
community in general (IOW, a luser). In turn, probably you will not
receive
as many replies as you could have received if you behaved accordingly,
and
so probably less (competent) help in the future.

This very basic polite behavior that is expected of you, and should
have
been clear to you already by mere application of common sense, is
called
Netiquette -- network etiquette.

See also http://www.jibbering.com/faq/faq_notes/clj_posts.html

This has been my last attempt to explain the situation to you.


HTH

PointedEars

Someone seriously needs a life
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top