<script language="javascript" type="text/javascript">
var Time;
var MyServerTime;
$(function() {
GetServerTime();
});
var tt;
//获得服务器时间和设置当前期号
function GetServerTime() {
var rand = Math.random();
$.get("getservertime/getime.aspx?radn=" + rand, { Action: "get", Name: "lulu" }, function(data, textStatus) {
this;
NowServerTime(data);
});
}
function NowServerTime(data) {
Time = data;
ServerTimeCode();
}
var Rowdata;
function ServerTimeCode() {
Rowdata = "2009-6-12 21:50:00"
var ServerTime = new Date(Date.parse(Time.replace(/-/g, "/")));
var NowTime = new Date(Date.parse(Rowdata.replace(/-/g, "/")));
MyServerTime = NowTime - ServerTime;
Delete();
}
function Delete() {
MyServerTime=MyServerTime-1000;
var nH = Math.floor(MyServerTime / (1000 * 60 * 60)) % 24;
var nM = Math.floor(MyServerTime / (1000 * 60)) % 60;
var nS = Math.floor(MyServerTime / 1000) % 60;
var strTime = "";
if (nH <= 0 && nM <= 0 && nS <= 0) {
Rowdata = "2009-6-12 21:51:00"
clearTimeout(tt);
GetServerTime();
}
else {
if (nH >= 10) {
strTime = strTime + nH;
}
else {
strTime = strTime + "0" + nH;
}
if (nM >= 10) {
strTime = strTime + ":" + nM;
}
else {
strTime = strTime + ":0" + nM;
}
if (nS >= 10) {
strTime = strTime + ":" + nS;
}
else {
strTime = strTime + ":0" + nS;
}
$("#divTime").html(strTime);
}
tt= setTimeout(Delete, 1000);
}
</script>
我第一次跟服务器的时间对比是一秒一秒的减少是正常的 但是当时间为0的时候 我停止了 setTimout
再去获取一次服务器时间 为社么我的时间就2秒一减少了? 希望高手指点指点