Da Clock and Date Stuff
Page last modified: 02 July 2008
Source Code For The Date Time Script on The cpwww888 Site
Note that you need divs in your page named daDate and clock to get this working (To be picked up by the document.getElementById('daDate')..... and
document.getElementById('clock')........ The date last modified routine was not working on Blue Host's server -- because the server did not return the document.lastModified. We have kept the javascript code to handle it in this script -- but it is commented out so as it is not 'live" -- we use a PHP script to get the last modified date that you see on a page. The Chinese days of the week show on MOST but not all machines.
/* ******************************************************************
& startTime - originally based on the W3 Schools Tut
* Added lots more into it! Got ideas for some of the
* syntax on the date modified from www.braemoor.co.uk
* ******************************************************************/
function startTime() {
/* ******************************************************
* Arrays For Days of Week (English and Chinese)
* and for suffixes across a month 1st, 2nd, 3rd, 4th etc
* and for the months of the year
* ******************************************************/
var weekday = new Array(7);
weekday[0] = "Sunday";
weekday[1] = "Monday";
weekday[2] = "Tuesday";
weekday[3] = "Wednesday";
weekday[4] = "Thursday";
weekday[5] = "Friday";
weekday[6] = "Saturday";
var chineseDay = new Array(7);
chineseDay[0] = "星期日";
chineseDay[1] = "星期一";
chineseDay[2] = "星期二";
chineseDay[3] = "星期三";
chineseDay[4] = "星期四";
chineseDay[5] = "星期五";
chineseDay[6] = "星期六";
var daySuffix = new Array(31);
daySuffix[1] = "st";
daySuffix[2] = "nd";
daySuffix[3] = "rd";
for (i=4;i<21; i++) {
daySuffix[i] ="th";}
daySuffix[21] = "st";
daySuffix[22] = "nd";
daySuffix[23] = "rd";
for (i=24;i<31; i++) {
daySuffix[i] ="th";}
daySuffix[31] = "st";
var months = new Array(12);
months[0] = "January";
months[1] = "February";
months[2] = "March";
months[3] = "April";
months[4] = "May";
months[5] = "June";
months[6] = "July";
months[7] = "August";
months[8] = "September";
months[9] = "October";
months[10] = "November";
months[11] = "December";
/* **************************************************
* Variables for processing the date and time (clock)
* **************************************************/
var today = new Date();
var h = today.getHours();
var m = today.getMinutes();
var s = today.getSeconds();
var d = today.getDate();
var month = today.getMonth();
var y = today.getYear();
/* ***************************************
* Do the Clock Here - start by adding
* a Zero in Front of the Numbers < 10
* ***************************************/
m = checkTime(m);
s = checkTime(s);
document.getElementById('clock').innerHTML = h + " : "+ m +" : "+ s;
t = setTimeout('startTime()',500);
/* ********************************************
* And now for Today's Date with the Day of the
* Week up front in Chinese, then in English
* ********************************************/
document.getElementById('daDate').innerHTML = chineseDay[today.getDay()] + weekday[today.getDay()] + " "+ d +daySuffix[d] + " " + months[month] + " "+y;
/* ***************************************************************************************
* And last -- the date when the page was "Last Modified" -- have to parse it or we end up
* with the American month-day-year format! Start by setting up variables for the day
* of the month, the month, the year, and the day of the week
* Switched to a php function instead -- but keep the code for future use. Still need to
* add a day suffix to the php code
* ***************************************************************************************
modDate = new Date(Date.parse(document.lastModified));
var d_lm = modDate.getDate();
var month_lm = modDate.getMonth();
var y_lm = modDate.getYear();
var z = modDate.getDay();
document.getElementById('lastUpdated').innerHTML = "Page last updated on " + weekday[z]
+ " "+ d_lm +daySuffix[d_lm] + " " + months[month_lm] + " "+ y_lm; */
} /* ************* End of startTime ********************/
/* ********************************************
* The "Zero Adderer On Thingy" (For the Clock)
* ********************************************/
function checkTime(i) {
if (i<10) {
i = "0" + i;
}
return i;
} /* ************* End of checkTime ********************/