html页面时间显示

解决问题

让页面上显示的时间像数字时钟一样。

系统时间:




var myDate =new Date();//使用13位的时间戳,参数为空默认显示本机时间
function xgtime(){
        myDate.setSeconds(myDate.getSeconds()+1);
        var showyear=myDate.getFullYear();
        var showmonth=myDate.getMonth()+1;
        if(showmonth<10)showmonth="0"+showmonth;
        var showdate=myDate.getDate();
        if(showdate<10)showdate="0"+showdate;
        var showhour=myDate.getHours();
        if(showhour<10)showhour="0"+showhour;
        var showminutes=myDate.getMinutes();
        if(showminutes<10)showminutes="0"+showminutes;
        var showseconds=myDate.getSeconds();
        if(showseconds<10)showseconds="0"+showseconds;

        var showtime=showyear+"-"+showmonth+"-"+showdate+" "+showhour+":"+showminutes+":"+showseconds;
        document.getElementById("endtime_innerHTML").innerHTML=showtime;
    }
    setInterval(xgtime,1000);


你可能感兴趣的:(html页面时间显示)