根据地区不同显示时间的javascript代码

时间:2021-05-18

bytingting

<scriptlanguage="JavaScript">
<!--Begin
vartimerRunning=false;
vartimezone="格林尼治标准时间";
varadjust=0;

functiontimeCheck(tzone,diff){
if(timerRunning){
clearTimeout(updatetime);
timerRunning=false;}
gmtOffset=eval(diff+adjust);
timezone=tzone;
checkDateTime();
}

functioncheckDateTime(){
vartoday=newDate();
varyear=today.getYear()+00;
varmonth=today.getMonth()+1;
vardate=today.getDate();
varday=today.getDay();
varhour=today.getHours();
varminute=today.getMinutes();
varsecond=today.getSeconds();

varlastSat=date-(day+1);
while(lastSat<32)lastSat+=7;
if(lastSat>31)lastSat+=-7;
varfirstSat=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=(newDate()).getTimezoneOffset();
yourOffset=yourOffset+adjust;

varxx=navigator.appName
varxy=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);
varhalf=eval(ourDifference%60);
ourDifference=Math.round(ourDifference/60);
hour=eval(hour-ourDifference);
varm=newArray("",
"1","2","3",
"4","5","6",
"7","8","9",
"10","11","12");
varleap=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;break;
}
}

vardateTime=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.clock.zonetime.value=dateTime;
document.clock.zonename.value=timezone;
updatetime=setTimeout("checkDateTime()",900);
timerRunning=true;
}
//End-->
</script>
<bodyOnLoad="timeCheck(timezone,0)">
<FORMname=clock>
当前的时间<INPUTsize=28name=zonetime>
<BR><BR>当前的地区<INPUTsize=21name=zonename><BR><BR>
<divstyle="background-color:#FF0000;width:100px;height:100px;"onmouseover="timeCheck('太平洋',+480)"></div>
<divstyle="background-color:#FF00FF;width:100px;height:100px;"onmouseover="timeCheck('夏威夷',+600)"></div>
</FORM>
</body>

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章