My 2 Cents Here is working and corrected script for showing current date on website

Status
Not open for further replies.

richardm55

White Belt
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.getFullYear()
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.
 

Marklen

Banned
The coding is perfect , it will be very well useful, can you tell which editor you use for coding pupose
 
Status
Not open for further replies.
Top