HTML+JavaScript显示当前时间

HTML:

JavaScript:

   var t=null;
   t=setTimeout(time,1000);   //设置定时器,一秒刷新一次
   function time(){
       clearTimeout(t);  //清楚定时器
       dt=new Date();
       var y=dt.getYear()+1900;
       var m=dt.getMonth()+1;
       var d=dt.getDate();
       var weekday=["星期日","星期一","星期二","星期三","星期四","星期五","星期六"];
       var day=dt.getDay();
       var h=dt.getHours();
       var min=dt.getMinutes();
       var s=dt.getSeconds();
       if(h<10){
           h="0"+h;
       }
       if(min<10){
           min="0"+min;
       }
       if(s<10){
           s="0"+s;
       }
       document.getElementById("timeShow").innerHTML= y + "年" + m + "月" + d + "日" + weekday[day] + "" + h + ":" + min + ":" + s + "";
       t = setTimeout(time, 1000);
   }

你可能感兴趣的:(html+css+js+框架)