Some time ago I have found script for showing present date on website. It worked properly for Mozilla but not for IE so I have corrected it. And here is below: DayName = new Array(7) DayName[0] = "Sunday " DayName[1] = "Monday " DayName[2] = "Tuesday " DayName[3] = "Wednesday " DayName[4] = "Thursday " DayName[5] = "Friday " DayName[6] = "Saturday " MonthName = new Array(12) MonthName[0] = "January " MonthName[1] = "February " MonthName[2] = "March " MonthName[3] = "April " MonthName[4] = "May " MonthName[5] = "June " MonthName[6] = "July " MonthName[7] = "August " MonthName[8] = "September " MonthName[9] = "October " MonthName[10] = "November " MonthName[11] = "December " function getDateStr(){ var Today = new Date() var WeekDay = Today.getDay() var Month = Today.getMonth() var Day = Today.getDate() var Year = Today.getYear() if( navigator.appName !== "Microsoft Internet Explorer" ) {Year += 1900} return DayName[WeekDay] + "," + " " + Day + " " + MonthName[Month] + ", " + Year } As you know you can insert this script either in head section using script tag or in external js file While in body section in place you want the date to appear you will write down this html code: <script language="JavaScript">document.write("Today is " + getDateStr())</script> I hope this code will be helpful for some people.
I am sorry guys but it was not my fault. When I put this code it was ok but after sending it was formatted so stupidly by this program. Anyway I will try to do it again and I must think to do it in better way
DayName = new Array(7) DayName[0] = "Sunday " DayName[1] = "Monday " DayName[2] = "Tuesday " Code (markup): formats nicer than DayName = new Array(7) DayName[0] = "Sunday " DayName[1] = "Monday " DayName[2] = "Tuesday " Adding some blank lines and spaces in your code helps make it more easily readable too. DayName[6] = "Saturday " MonthName = new Array(12) MonthName[0] = "January " function getDateStr(){ var Today = new Date(); var WeekDay = Today.getDay(); var Month = Today.getMonth(); var Day = Today.getDate(); var Year = Today.getYear(); if( navigator.appName !== "Microsoft Internet Explorer" ) {Year += 1900} return DayName[WeekDay] + ", " + Day + " " + MonthName[Month] + ", " + Year } Code (markup): BTW, just checking to make sure that the year is greater than 1999, and adding 1900 if it's not, eliminates some code. (new Date() will never be less than 2000 again until we change the calendar.)
Better to use: var Year = Today.getFullYear(); Code (markup): so that you eliminate the 19xx/20xx issue and makes the code reusable elsewhere.
You mean I just replace line var Year=Today.getYear(); with line var Year = Today.getFullYear(); and also I may remove next line if( navigator.appName !== "Microsoft Internet Explorer" ) {Year += 1900} because it is not needed now? I must check it if it really works on all browsers.
Lots of luck. You can check it on the most popular ones (IE [all versions back to 6 at least], Firefox, Chrome, Opera, Safari - and the popular ones used on Android phones), but there are a few hundred standard browsers and hundreds more that only a few people use. Knowing that at least one browser screwed the pooch on this one, I'd leave in the trivial code to make sure that the year was in the 3rd millennium.
I will check it on the most popular browsers only. If it does not work on rest of them it is not big matter.
Everyone may test that corrected code because it has been introduced on my website http://black2colour.weebly.com
If the page is being generated by PHP, doing it iin PHP will speed up the page load. If it's an html page, Javascript is the proper choice.