html页面时间显示

2017-11-09  本文已影响397人  洞房花猪

解决问题

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

<span>系统时间:<i id="endtime_innerHTML"></i></span>

<?php
function getMillisecond() {
    list($t1, $t2) = explode(' ', microtime());
    return $t2 * 1000 + ceil( ($t1 * 1000) );
}
$time = getMillisecond();
?>

</script>
var myDate =new Date(<?php echo $time;?>);//使用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);

</script>
上一篇 下一篇

猜你喜欢

热点阅读