Javascript display document last modified in locale date

  You are currently not logged in. You can view the forums, but cannot post messages. Log In | Register

24-May-13 11:19
I am a brand new beginner, just learning the basics of Javascript.
For days on end, I have been trying to find code that will display the date the webpage was last updated by the web author.

I have used the below function, however, I find the result defaults to UTC/GMT date when using document.lastModified (despite it being formatted to the local date). So the "look" of the date displays OK, but the date is always behind, showing UTC/GMT date, not AEST (Australian Eastern Standard Time).

I tried a few different date options, and below is how the code displays. 'a' and 'b' reference the document.last modified, but the results are not what I want. (When I updated the webpage where I placed my function, my computer clock showed it was Saturday 25 May 2013, 1:45am. (Again, I don't want the current date displayed on the browser, I want so show the date the webpage was last updated by the web author).

Also, I noticed that 'a' is updating the time each instance the browser is refreshed (which is not what I want, I want the date/time returned of the webpage last update by the web author).

This is not the result I want:
Date last updated using 'a': Fri May 24 2013 15:51:06 GMT+1000 (EST)
Date: 24 / Month: 5 / Year: 2013 / Hours: 15 / Minutes: 51 / Seconds: 6

This is not the result I want:
Date last updated using 'b': 24 May 2013

This is for reference/comparison only, showing current date:
Current date using 'c': Sat May 25 2013 01:51:06 GMT+1000 (EST)
Date: 25 / Month: 5 / Year: 2013 / Hours: 1 / Minutes: 51 / Seconds: 6

Code I used:


function dateUpdated() {

a = new Date(document.lastModified)

b = a.toLocaleDateString()

c = new Date

document.write ( "Date last updated using 'a': " + a + "<br>" +
" Date: " + a.getDate() + " / Month: " + (a.getMonth()+1) + " / Year: " + a.getFullYear() + " / Hours: " + a.getHours() + " / Minutes: " + a.getMinutes() + " / Seconds: " + a.getSeconds() + "<p>")

document.write ( "Date last updated using 'b': " + b + "<p>" )

document.write ( "Current date using 'c': " + c+ "<br>" +
" Date: " + c.getDate() + " / Month: " + (c.getMonth()+1) + " / Year: " + c.getFullYear() + " / Hours: " + c.getHours() + " / Minutes: " + a.getMinutes() + " / Seconds: " + c.getSeconds() + "<br>")

}
27-May-13 16:50
Scripted documents ARE "last modified" on, and at, the instant they are requested and therefore created.

--
Chris.
So long, and thanks for all the fish.
http://webmaster-talk.eu/
30-May-13 06:11
Hi, just a really stupid question, so I hope you can forgive me .....

If I wanted to show the date that the web author of the webpage last did a "static" change to the site, what is the best way to do this?

Should I just "manually" type in the date I want, rather than getting a script to do it?
30-May-13 12:28
Yep or use a CMS that records such information.

--
Chris.
So long, and thanks for all the fish.
http://webmaster-talk.eu/

 
New posts
Old posts

Follow Elated