Forum Moderators: open

Message Too Old, No Replies

javascript to display last page update?

         

kapow

9:55 am on May 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Is is possible to have a javascript that will show when a web page was last updated?

Alternative Future

10:05 am on May 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Do you mean something like this:

<script language="javascript">
document.write("<i>Last updated "+document.lastModified+"<I>");
</script>

-George

kapow

12:12 pm on May 24, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks

Is it possible to make it show the date in UK format ie date/month/year instead of US format?

and

add 5 hours to it (the site is hosted in the US but for a UK audience so I need to take account of the time difference)?

Alternative Future

12:46 pm on May 24, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi kapow,

The following displays the time in UK format. I am trying to get it to display EASTERN time as speak. But someone else might know and post it saving me ;-)

<script language="javascript">
var theDate = new Date(document.lastModified);
var ukDate = theDate.toGMTString();
document.write("<i>Last updated "+ukDate+"<I>");
</script>

-George

Alternative Future

1:15 pm on May 24, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Not had much time to test it fully but i think this works:

<script language="javascript">
months = ['January', 'Febraury', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
var theDate = new Date(document.lastModified);
theDate.setTime((theDate.getTime()+(5000*60*60)) )
with (theDate) {
document.write("<i>Last updated "+getDate()+' '+months[getMonth()]+' '+getYear()+' '+getHours()+':'+getMinutes()+":"+getSeconds()+"</i>")
}
</script>

Let's know if there are any problems...

-George

judithem

10:09 pm on Jun 1, 2004 (gmt 0)

10+ Year Member



Hi, George,
Hi all,

I'm, first off, a newbie.

Lately I've been hand keying in the silly updates, and that code you just wrote, is so close to what I could use, that I'll ask if you might alter it (Gosh I hope you're patient and have a moment too) so that it says

Last updated: 1 June 2004

to match good old Eastern Standard Time,
without seconds?

Much thanks for reading this l'il post,

JudithEm

judithem

12:37 pm on Jun 11, 2004 (gmt 0)

10+ Year Member



As to the Automatic Page Modified Line:

I like George's suggestion

<script language="javascript">
document.write("<i>Last updated "+document.lastModified+"<I>");
</script>

a great deal. It's elegant.

If I wanted the seconds off of it, how I would alter the script?

[Thanks In Advance]

Alternative Future

12:58 pm on Jun 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi judithem,

Sorry I missed your first post! Anyway...

The script with the removal of seconds is:
<script language="javascript">
months = ['January', 'Febraury', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
var theDate = new Date(document.lastModified);
theDate.setTime((theDate.getTime()+(5000*60*60)) )
with (theDate) {
document.write("<i>Last updated "+getDate()+' '+months[getMonth()]+' '+getYear()+' '+getHours()+':'+getMinutes()+"</i>")
}
</script>

And with just the date with no time attached it is:
<script language="javascript">
months = ['January', 'Febraury', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
var theDate = new Date(document.lastModified);
theDate.setTime((theDate.getTime()+(5000*60*60)) )
with (theDate) {
document.write("<i>Last updated "+getDate()+' '+months[getMonth()]+' '+getYear()+"</i>")
}
</script>
To help get eastern time I require the location of where your site is hosted! If it is hosted in the required time zone then you can remove most of the above script. I'll help you out once you have replied with the location.

-George