首页 新闻 会员 周边 捐助

js 获得服务器时间循环倒计时

0
悬赏园豆:30 [已关闭问题] 关闭于 2009-06-12 20:45

<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秒一减少了? 希望高手指点指点

问题补充: 我自己搞定了?!
烈焰_闹闹的主页 烈焰_闹闹 | 初学一级 | 园豆:65
提问于:2009-06-11 22:49
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册