js -- 网站运行时间


你若与我化风,我便为你成龙


实现效果

上面的是动态刷新的,下面的是静态的,需要手动刷新才会更新


动态代码

<script data-no-instant=""> 

    function show_date_time() {
        window.setTimeout("show_date_time()",1e3);
        var BirthDay=new Date("August 15,2017 18:19:35"),
        today=new Date,
        timeold=today.getTime()-BirthDay.getTime(),
        msPerDay=864e5,
        e_daysold=timeold/msPerDay,
        daysold=Math.floor(e_daysold),
        e_hrsold=24*(e_daysold-daysold),
        hrsold=Math.floor(e_hrsold),
        e_minsold=60*(e_hrsold-hrsold),
        minsold=Math.floor(60*(e_hrsold-hrsold)),
        seconds=Math.floor(60*(e_minsold-minsold));
        span_dt_dt.innerHTML="<font color=black>"+daysold+"</font> 天 <font color=black>"+hrsold+"</font> 时 <font color=black>"+minsold+"</font> 分 <font color=black>"+seconds+"</font> 秒";} 
    show_date_time();

</script>

<p style="color: grey;"><h6>本站已运行: <span id="span_dt_dt"></span></h6></p>

静态代码

<p style="color: grey;"><h6>本站已运行:
        <span>
            <script>
                BirthDay=new Date("August 15,2017 18:19:35");
                today=new Date();
                timeold=(today.getTime()-BirthDay.getTime());
                sectimeold=timeold/1000;
                secondsold=Math.floor(sectimeold);
                msPerDay=24*60*60*1000;

                /*获取天数*/
                e_daysold=timeold/msPerDay;
                daysold=Math.floor(e_daysold);

                /*获取小时数*/
                e_hrsold=(daysold-e_daysold)*-24;
                hrsold=Math.floor(e_hrsold);

                /*获取分钟数*/
                e_minsold=(hrsold-e_hrsold)*-60;
                minsold=Math.floor((hrsold-e_hrsold)*-60);

                /*获取秒数*/
                seconds=Math.floor((minsold-e_minsold)*-60);

                document.write("<font color=black>"+daysold+"</font> 天 <font color=black>"+hrsold+"</font> 时 <font color=black>"+minsold+"</font> 分 <font color=black>"+seconds+"</font> 秒");
            </script>
        </span></h6> 
    </p>

    <p style="color:grey;"><h6>@Copyright 2017 by pinsily,@Power by typecho</h6></p>