var todayDay = -1; function updateTime() { Today = new Date(); Todays_Year = Today.getYear(); Todays_Month = Today.getMonth() + 1; //Computes the time difference between the client computer and the server. Server_Date = (new Date(2010, 3, 12, 3, 41, 55)).getTime(); Todays_Date = (new Date(Todays_Year, Todays_Month, Today.getDate(), Today.getHours(), Today.getMinutes(), Today.getSeconds())).getTime(); computeTime(Server_Date-Todays_Date); } function computeTime(time_difference) { Today = new Date(); Todays_Year = Today.getYear(); Todays_Month = Today.getMonth() + 1; //Convert today's date and the target date into miliseconds. Todays_Date = (new Date(Todays_Year, Todays_Month, Today.getDate(), Today.getHours(), Today.getMinutes(), Today.getSeconds())).getTime(); //Convert that into seconds. //Taking into account the time differential between the client computer and the server. Time_UTC_plus_8 = new Date(); Time_UTC_plus_8.setTime(Todays_Date + time_difference); days = Time_UTC_plus_8.getDate(); if (todayDay == -1) { todayDay = days; } else if (todayDay != days) { window.location.reload(); } hours = Time_UTC_plus_8.getHours(); minutes = Time_UTC_plus_8.getMinutes(); seconds = Time_UTC_plus_8.getSeconds(); document.getElementById("servertime").innerHTML = hours + '时' + minutes + '分' + seconds + '秒'; //Recursive call, keeps the clock ticking. setTimeout('computeTime('+time_difference+');', 1000); }