Jump to content
Terrum

How to make an automatic "Last Updated" date/time in HTML

Recommended Posts

Hey, I've been making this site for some time now. The layout is "Last Updated: Thursday 18th February, 2010 | 13:39 GMT" But I have to keep changing it everytime I edit the page. Is there a way to make it do it automatically from the local time when saving a page? Thanks.

Share this post


Link to post
Share on other sites

I think you need a Javascript script, like one of these:

 

www.javascriptkit.com/script/cutindex1.shtml

 

Thanks for the link. But minutes of searching I couldn't find one that would work as a "Last Updated" feature. Thanks though. Any other people able to help me?

 

EDIT: Okay i see loads here http://www.google.co.uk/search?q=last+updated+javascript&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-GB:official&client=firefox-a But is there one someone can edit for me that will write it exactly like this "Last Updated: Thursday 18th February, 2010 | 13:39 GMT" Thanks.

Share this post


Link to post
Share on other sites

There's some code at the bottom of http://www.webmaster...orum91/1781.htm which I think does what you want.

 

For the timezone bit, will it always be GMT or do you want it to display the timezone of the visitor?

 

If it's always GMT, I imagine the following code (from the link above) would work (not tested, just did a quick google):

 

<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()+" GMT</i>") 
} 
</script> 

Share this post


Link to post
Share on other sites

There's some code at the bottom of http://www.webmaster...orum91/1781.htm which I think does what you want.

 

For the timezone bit, will it always be GMT or do you want it to display the timezone of the visitor?

 

If it's always GMT, I imagine the following code (from the link above) would work (not tested, just did a quick google):

 

<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()+" GMT</i>") 
} 
</script> 

 

Absolutely perfect. Thanks. But one problem. I edited it to the way I liked it

 

<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("Last Updated: "+getDate()+' '+months[getMonth()]+', '+getYear()+' | '+getHours()+':'+getMinutes()+" GMT") 
} 
</script>

But the Year doesn't work.

 

The results come out as: Last Updated: 21 Febraury, 110 | 21:30 GMT

 

110??? Please help. Thanks.

 

Also the timezone is wrong, it says 21:30 GMT when I didn't do it at that time, It was like 15:30 I last edited it

 

Also is there a possible way to add the date too? (Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday)

 

Check my site at www.terrum.co.uk to see the script in preview and please help my issues. Thanks alot.

Share this post


Link to post
Share on other sites

Just modified code slightly

 

<script language="javascript"> 
months = ['January', 'Febraury', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']; 
var d=new Date();
var weekday=new Array(7);
weekday[0]="Sunday";
weekday[1]="Monday";
weekday[2]="Tuesday";
weekday[3]="Wednesday";
weekday[4]="Thursday";
weekday[5]="Friday";
weekday[6]="Saturday";

var d = new Date();
(d.getFullYear());


var theDate = new Date(document.lastModified); 
theDate.setTime((theDate.getTime()+(60*60)) ) 
with (theDate) { 
document.write("<i>Last updated "+weekday[getDay()]+' '+getDate()+' '+months[getMonth()]+' '+d.getFullYear()+' '+getHours()+':'+getMinutes()+" GMT</i>") 
} 
</script> 

 

Pat

Share this post


Link to post
Share on other sites

Just modified code slightly

 

<script language="javascript"> 
months = ['January', 'Febraury', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']; 
var d=new Date();
var weekday=new Array(7);
weekday[0]="Sunday";
weekday[1]="Monday";
weekday[2]="Tuesday";
weekday[3]="Wednesday";
weekday[4]="Thursday";
weekday[5]="Friday";
weekday[6]="Saturday";

var d = new Date();
(d.getFullYear());


var theDate = new Date(document.lastModified); 
theDate.setTime((theDate.getTime()+(60*60)) ) 
with (theDate) { 
document.write("<i>Last updated "+weekday[getDay()]+' '+getDate()+' '+months[getMonth()]+' '+d.getFullYear()+' '+getHours()+':'+getMinutes()+" GMT</i>") 
} 
</script> 

 

Pat

Thanks so much! Can't be any happier.

Share this post


Link to post
Share on other sites
On 21/02/2010 at 7:48 PM, Terrum said:

Thanks so much! Can't be any happier.

 

On 21/02/2010 at 5:43 PM, pat24 said:

Just modified code slightly

 

 


<script language="javascript"> 
months = ['January', 'Febraury', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']; 
var d=new Date();
var weekday=new Array(7);
weekday[0]="Sunday";
weekday[1]="Monday";
weekday[2]="Tuesday";
weekday[3]="Wednesday";
weekday[4]="Thursday";
weekday[5]="Friday";
weekday[6]="Saturday";

var d = new Date();
(d.getFullYear());


var theDate = new Date(document.lastModified); 
theDate.setTime((theDate.getTime()+(60*60)) ) 
with (theDate) { 
document.write("<i>Last updated "+weekday[getDay()]+' '+getDate()+' '+months[getMonth()]+' '+d.getFullYear()+' '+getHours()+':'+getMinutes()+" GMT</i>") 
} 
</script> 
 

 

 

Pat

Love this! Thank you so much!

Just one thing - I've added seconds, but it doesn't add a zero below 10 seconds.

E.g. 19:47:3 (instead of 19:47:03). Any ideas please?

 

<script language="javascript"> 
months = ['January', 'Febraury', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']; 
var d=new Date();
var weekday=new Array(7);
weekday[0]="Sunday";
weekday[1]="Monday";
weekday[2]="Tuesday";
weekday[3]="Wednesday";
weekday[4]="Thursday";
weekday[5]="Friday";
weekday[6]="Saturday";

var d = new Date();
(d.getFullYear());


var theDate = new Date(document.lastModified); 
theDate.setTime((theDate.getTime()+(60*60)) ) 
with (theDate) { 
document.write("<i>Last updated: "+weekday[getDay()]+', '+getDate()+' '+months[getMonth()]+' '+d.getFullYear()+';<br> '+getHours()+':'+getMinutes()+":"+getUTCSeconds()+" GMT</i>") 

</script> 

 

 

Cheers,

Ash

 

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.

  • Recently Browsing

    No registered users viewing this page.

  • Member Statistics

    • Total Members
      57,548
    • Most Online
      4,970

    Newest Member
    FredsHead
    Joined
  • Forum Statistics

    • Total Topics
      65,738
    • Total Posts
      455,458
×