Hi,
I use the following code to display the "Last Saved" or should I say "Page Updated" date on my webpages. The code displays the date in "10/08/2004" format.
// Javascript @ Beert.be
// http://www.beert.be/javascript/
var date = new Date(document.lastModified);
var day = date.getDate();
var month = [date.getMonth() + 1];
var year = date.getYear();
if (day < 10) day = "0" + day;
if (month < 10) month = "0" + month;
if (year < 2000) year += 1900;
document.write(day + "/" + month + "/" + year);
What I'd like to do is modify this code so that it displays the date in "10 August 2004" format. I can see that the month variable simply needs changing to be assigned a name, but I don't know how to program this. Can anyone help?
Javascript Date Question
<!-- Begin
var days = new Array(8);
days[1] = "Sunday";
days[2] = "Monday";
days[3] = "Tuesday";
days[4] = "Wednesday";
days[5] = "Thursday";
days[6] = "Friday";
days[7] = "Saturday";
var months = new Array(13);
months[1] = "January";
months[2] = "February";
months[3] = "March";
months[4] = "April";
months[5] = "May";
months[6] = "June";
months[7] = "July";
months[8] = "August";
months[9] = "September";
months[10] = "October";
months[11] = "November";
months[12] = "December";
var dateObj = new Date(document.lastModified)
var wday = days[dateObj.getDay() + 1]
var lmonth = months[dateObj.getMonth() + 1]
var date = dateObj.getDate()
var fyear = dateObj.getYear()
if (fyear < 2000)
fyear = fyear + 1900
document.write(wday + ", " + lmonth + " " + date + ", " + fyear)
// End -->
This will sort out the day and month
Javascript Date Question
Hi Stu,
Thanks for that solution. The only problem is, I think you over-engineered it a little. Using that code, the last saved date is displayed as "Friday, August 6, 2004". What I want it to do is display as "06 August 2004".
Could you please edit your code to make it do this? I really know nothing about JavaScript, so I would appreciate your help.
Javascript Date Question
Hi there,
So, can anyone help me with this one? Or is this perhaps not the best place to ask?
Javascript Date Question
Just a minor tweak (which perhaps you may have attempted )
<!-- Begin
var months = new Array(13);
months[1] = "January";
months[2] = "February";
months[3] = "March";
months[4] = "April";
months[5] = "May";
months[6] = "June";
months[7] = "July";
months[8] = "August";
months[9] = "September";
months[10] = "October";
months[11] = "November";
months[12] = "December";
var dateObj = new Date(document.lastModified)
var lmonth = months[dateObj.getMonth() + 1]
var date = dateObj.getDate()
if (date <10 )
date = "0" + date
var fyear = dateObj.getYear()
if (fyear < 2000)
fyear = fyear + 1900
document.write(date + " " + lmonth + " " + fyear)
// End -->
If this is a new web site then you can safely delete the two lines
if (fyear < 2000)
fyear = fyear + 1900
as these are put in for pages last updated pre 2000
Javascript Date Question
Bravo Stu,
That works perfectly. Thank you very much indeed. I'll have a closer look through the code later on, to try and understand it, even if I know nothing about JavaScript
Alan
Javascript Date Question
Sorry, small error in my last post.
If this is a new web site then you can safely delete the two lines
if (fyear < 2000)
fyear = fyear + 1900
as these are put in for pages last updated pre 2000
Should have been ~
You will NEED the two lines
if (fyear < 2000)
fyear = fyear + 1900
To display the year correctly in FF etc