<body>
<input type=text name=zonetime size=28>
<br>
<br>
<b>当前的地区</b><br>
<input type=text name=zonename size=21>
<br>
<br>
<input type=button value="太平洋" onClick="timeCheck(this.value, -480)" name="button">
<input type=button value="北京" onClick="timeCheck(this.value, 480)" name="button">
<input type=button value="东京" onClick="timeCheck(this.value, 540)" name="button">
<input type=button value="伦敦" onClick="timeCheck(this.value, +0)" name="button">
</body>
<script language="JavaScript">
<!-- Begin
var timerRunning = false;
var timezone = "格林尼治标准时间";
var timearea = document.getElementById("zonetime");
var zonenamearea = document.getElementById("zonename");
zonenamearea.value = timezone;
var timediff = 0;function window.onload(){drawTime();}function timeCheck(aa,bb)
{
zonenamearea.value = aa;
timediff = bb;
}function drawTime()
{
var now = new Date();
now.addMinute(timediff);
timearea.value = now.Format("MM/dd/yyyy hh:mm:ss")
setTimeout("drawTime()",300);
}Date.prototype.addMinute = function(num){this.setMinutes(this.getMinutes() + num);return this;}Date.prototype.Format = function()
{
year = this.getUTCFullYear();
month = this.getUTCMonth()+1;
day = this.getUTCDate();
hour = this.getUTCHours();
minute = this.getUTCMinutes();
second = this.getUTCSeconds();
month = (month<10?"0":"") + month;
day = (day<10?"0":"") + day;
minute = (minute<10?"0":"") + minute;
second = (second<10?"0":"") + second;
str = month + "/" + day + "/" + year + " " + hour + ":" + minute + ":" + second;
return str;
}
// End -->
</script>
<input type=text name=zonetime size=28>
<br>
<br>
<b>当前的地区</b><br>
<input type=text name=zonename size=21>
<br>
<br>
<input type=button value="太平洋" onClick="timeCheck(this.value, -480)" name="button">
<input type=button value="北京" onClick="timeCheck(this.value, 480)" name="button">
<input type=button value="东京" onClick="timeCheck(this.value, 540)" name="button">
<input type=button value="伦敦" onClick="timeCheck(this.value, +0)" name="button">
</body>
<script language="JavaScript">
<!-- Begin
var timerRunning = false;
var timezone = "格林尼治标准时间";
var timearea = document.getElementById("zonetime");
var zonenamearea = document.getElementById("zonename");
zonenamearea.value = timezone;
var timediff = 0;function window.onload(){drawTime();}function timeCheck(aa,bb)
{
zonenamearea.value = aa;
timediff = bb;
}function drawTime()
{
var now = new Date();
now.addMinute(timediff);
timearea.value = now.Format("MM/dd/yyyy hh:mm:ss")
setTimeout("drawTime()",300);
}Date.prototype.addMinute = function(num){this.setMinutes(this.getMinutes() + num);return this;}Date.prototype.Format = function()
{
year = this.getUTCFullYear();
month = this.getUTCMonth()+1;
day = this.getUTCDate();
hour = this.getUTCHours();
minute = this.getUTCMinutes();
second = this.getUTCSeconds();
month = (month<10?"0":"") + month;
day = (day<10?"0":"") + day;
minute = (minute<10?"0":"") + minute;
second = (second<10?"0":"") + second;
str = month + "/" + day + "/" + year + " " + hour + ":" + minute + ":" + second;
return str;
}
// End -->
</script>
我修改的代码如下,哪里不对,请指教。
<script language="javascript">
<!-- Begin
var timerRunning = false;
var timezone = "格林尼治标准时间";
var adjust = 0;function timeCheck(diff) {
if (timerRunning) {
clearTimeout(updatetime);
timerRunning = false; }
gmtOffset=eval(diff+adjust);
//timezone = tzone;
checkDateTime();
}function checkDateTime () {
var today = new Date();
var year = today.getYear() + 00;
var month = today.getMonth()+1;
var date = today.getDate();
var day = today.getDay();
var hour = today.getHours();
var minute = today.getMinutes();
var second = today.getSeconds(); var lastSat = date - (day+1);
while (lastSat < 32) lastSat+=7;
if (lastSat > 31) lastSat+=-7;
var firstSat = date - (day+1);
while (firstSat > 0) firstSat+=-7;
if (firstSat < 1) firstSat+=7;
if ((((month == 4) && (date >= firstSat)) || month > 4) &&
(month < 11 || ((month == 10) && day <= lastSat))) adjust += 60;
yourOffset = (new Date()).getTimezoneOffset();
yourOffset = yourOffset + adjust; var xx = navigator.appName
var xy = navigator.appVersion;
xy = xy.substring(0,1);
if ((xy == 4) && (xx == "Netscape")) yourOffset = yourOffset+adjust;
if ((((month == 4) && (date > 20)) || month > 4) && (month < 11 || ((month == 10) &&day < 30))) adjust -= 60; ourDifference = eval(gmtOffset - yourOffset);
var half = eval(ourDifference % 60);
ourDifference = Math.round(ourDifference / 60);
hour = eval(hour - ourDifference);
var m = new Array("","1","2","3","4","5","6","7","8","9","10","11","12");
var leap = eval(year % 4); if ((half == -30) || (half == 30)) minute += 30;
if (minute > 59) minute -= 60, hour++;
if (minute < 0) minute += 60, hour--;
if (hour > 23) hour -= 24, date += 1;
if (((month == 4) || (month == 6) || (month == 9) || (month == 11)) && (date==31)) date = 1, month ++;
if (((month == 2) && (date > 28)) && (leap != 0)) date = 1, month ++;
if ((month == 2) && (date > 29)) date = 1, month++;
if (hour < 0) hour += 24, date --;
if ((date == 32) && (month == 12)) month = m[1], date = 1, year++;
if (date == 32) date = 1, month++;
if ((date < 1) && (month == 1)) month= m[12], date = 31, year--;
if (date < 1) date = 31, month --;
if (((month == 4) || (month == 6) ||(month== 9) || (month == 11)) && (date == 31)) date = 30;
if ((month == 2) && (date > 28)) date = 29;
if (((month == 2) && (date > 28)) && (leap != 0)) date=28;
for (i=1; i<13; i++)
{ if (month == i) {month = m[i]; break; }
} var dateTime = hour;
dateTime = ((dateTime < 10) ? "0":"") + dateTime;
dateTime = " " + dateTime;
dateTime += ((minute < 10) ? ":0" : ":") + minute;
dateTime += ((second < 10) ? ":0" : ":") + second;
dateTime += (hour >= 12) ? "下午, " : "上午, ";
dateTime += year + "年" + month + "月" + date + "日" ; document.write(datetime);
//document.clock.zonename.value = timezone;
updatetime=setTimeout("checkDateTime()", 900);
timerRunning = true;
}
// End -->
</script><table width="700" border="1"><tr height="20"><td width="200"></td>
<td width="200">太平洋<script>timeCheck(+480); document.write(dateTime )</script></td>
</tr>
<tr height="20"><td width="200"></td>
<td width="200">中心<script>timeCheck(+420); document.write(dateTime )</script></td>
</tr>
<tr height="20"><td width="200"></td>
<td width="200">北京<script>timeCheck(-420); document.write(dateTime )</td>
</tr>
<tr height="20"><td width="200"></td>
<td width="200">东京<script>timeCheck(-540); document.write(dateTime )</td>
</tr>
</table>
<tr>
<td width="101" align="center">太平洋</td>
<td width="193" align="center" timediff="-480"> </td>
</tr>
<tr>
<td align="center">北京</td>
<td align="center" timediff="480"> </td>
</tr>
<tr>
<td align="center">东京</td>
<td align="center" timediff="540"> </td>
</tr>
<tr>
<td align="center">伦敦</td>
<td align="center" timediff="0"> </td>
</tr>
</table>
</body>
<script language="JavaScript">
<!-- Begin
//只要是带 timediff属性 的表格单元 就会按照里面的时间差(分钟)变化
var timeout = 300;//这个是刷新频率(毫秒)
var clockArr = new Array();function window.onload()
{
var clocks = document.getElementById("Clocks");
if(clocks!=null && clocks.tagName=="TABLE")
{
for(var i=0;i<clocks.cells.length;i++)
{
var otd = clocks.cells[i];
var tempstr = otd.getAttribute("timediff");
if(tempstr!=null && !isNaN(tempstr))
{
clockArr.push(new clock(tempstr,otd));
}
}
}
setTimeout("drawTime()",timeout);
}function drawTime()
{
for(var i=0;i<clockArr.length;i++)
{
clockArr[i].drawTime();
}
setTimeout("drawTime()",timeout);
}function clock(timediff,timearea)
{
this.timeDiff = parseInt(timediff);
this.timeArea = timearea;
this.drawTime = function()
{
if(this.timeArea!=null && this.timeArea.innerText!=null)
{
time = new Date();
time.addMinute(this.timeDiff);
this.timeArea.innerText = time.Format("MM/dd/yyyy hh:mm:ss")
}
}
}Date.prototype.addMinute = function(num){this.setMinutes(this.getMinutes() + num);return this;}
Date.prototype.Format = function()
{
year = this.getUTCFullYear();
month = this.getUTCMonth()+1;
day = this.getUTCDate();
hour = this.getUTCHours();
minute = this.getUTCMinutes();
second = this.getUTCSeconds();
month = (month<10?"0":"") + month;
day = (day<10?"0":"") + day;
minute = (minute<10?"0":"") + minute;
second = (second<10?"0":"") + second;
str = month + "/" + day + "/" + year + " " + hour + ":" + minute + ":" + second;
return str;
}
// End -->
</script>