html页面时间显示

解决问题

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

<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>
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,640评论 25 708
  • 问答题47 /72 常见浏览器兼容性问题与解决方案? 参考答案 (1)浏览器兼容问题一:不同浏览器的标签默认的外补...
    _Yfling阅读 13,815评论 1 92
  • 这道题跟Knapsack 问题非常相似, 但是难度上有很大的升级。 首先, 这个不是课本上的例子,我们得自己做出了...
    98Future阅读 731评论 0 0
  • 我有时候很霸道 总是以我以为对你好的方式 要求你 也很自私的希望 你能全部听我的 我不知道这样的我 能不能收起自己...
    哀慕熙荣阅读 236评论 0 1
  • 儿子换牙了,无意中发现儿子整整齐齐的牙齿出现了一个洞,我惊喜到:“宝贝,你要换牙了,你掉了一颗牙!快来快来,对着镜...
    草莓冫氵阅读 238评论 0 0