Forum Moderators: open
I have a script that I purchased from a company in Russia and their date format is (year,month,day) this is what it looks like now:
Last updated on 2003-07-19
Copyright © 2001-2003
I want to change the script so that the date is displayed (month,day,year)
I want it to look like this:
Last updated on 07-19-2003 or July 19, 2003
Copyright © 2001-2003
I have been told I need to change something in img/lib.js - bottom of GetCurDate()
function
Can someone please tell me exactly what has to be changed, here is that part of the script:
function GetCurDate() {
var today = new Date();
var date = today.getDate();
var day = today.getDay();
var month = today.getMonth();
var year = today.getYear();
var dayName;
var daySuffix;
var monthName;
if (day == 0) dayName = "Sunday";
else if (day == 1) dayName = "Monday";
else if (day == 2) dayName = "Tuesday";
else if (day == 3) dayName = "Wednesday";
else if (day == 4) dayName = "Thursday";
else if (day == 5) dayName = "Friday";
else if (day == 6) dayName = "Saturday";
if (month == 0) monthName = "January";
else if (month == 1) monthName = "February";
else if (month == 2) monthName = "March";
else if (month == 3) monthName = "April";
else if (month == 4) monthName = "May";
else if (month == 5) monthName = "June";
else if (month == 6) monthName = "July";
else if (month == 7) monthName = "August";
else if (month == 8) monthName = "September";
else if (month == 9) monthName = "October";
else if (month == 10) monthName = "November";
else if (month == 11) monthName = "December";
return (dayName + " " + monthName + " " + date + ", " + year);
}
To return a 4 digit year xbrowser you need this:
dateObj.getFullYear()
Anyway, this function looks like a good learning tool so I've picked it apart a bit for you.
This part at the bottom of the function makes and returns the date string when GetCurDate() is called
return (dayName + " " + monthName + " " + date + ", " + year);
The brackets around this statement are unneccecary. It can look like this:
return dayName + " " + monthName + " " + date + ", " + year;
spelt out it's saying return the following:
"dayName plus a space plus monthName plus a space plus date plus a comma followed by a space plus year"
To modify it to this:
07-19-2003
you don't need dayName or monthName and the spaces need to be changed to dashes. There's lots of ways to do this but I'll modify your function to help you understand it.
function GetCurDate() {
var today = new Date();
var date = today.getDate();
var month = today.getMonth();
var year = today.getFullYear();
var monthNumber;
if (month == 0) monthNumber = "01";
else if (month == 1) monthNumber = "02";
else if (month == 2) monthNumber = "03";
else if (month == 3) monthNumber = "04";
else if (month == 4) monthNumber = "05";
else if (month == 5) monthNumber = "06";
else if (month == 6) monthNumber = "07";
else if (month == 7) monthNumber = "08";
else if (month == 8) monthNumber = "09";
else if (month == 9) monthNumber = "10";
else if (month == 10) monthNumber = "11";
else if (month == 11) monthNumber = "12";
return monthNumber + "-" + date + "-" + year;
}
To see how things work you can put in an alert after a statement. try this:
var month = today.getMonth();
alert(month);
Which is what needs to be done but he doesn't tell me what to alter .....lol
anyways enough ****ing.... I tired to copy and paste what you said into the doc but it didn't change anything. Could you please post the part of the script again exactly how it should be so I can copy and paste it into the doc.. I appreciate you trying to explain it to me but I just don't understand scripts at all... Thanks for any and all help
Changing to a format like 01-12-2003 introduces an ambiguity. Europeans read it as 1st December, whilst in the US and parts of Canada they interpret it as January 12th.
See also RFC 3339 - Date and Time on the Internet, by Chris Newman and Graham Klein and [webmasterworld.com...] .
That function is not being used to write the 'last update' text of the page. To find out what part of the code is the part that needs to be changed, search for "Last updated".
Just out of interest, what does the application do? (I'm sure that for $700 you did not just buy a script to modify your 'last updated' date ;)
Shawn
As Shawn pointed out it looks like we’re changing the wrong function.
I'll be unable to answer you for atleast the next 12 - 16 hours. Read that thread and if you still want things changed post the relevant function(s). In the mean time, if anyone wants to jump in feel free to do so.