zblog 博客如何在网页底部添加显示网站运行时长代码

1、代码模板(直接套用):找到站点目录文件 footer.php  添加即可。

    

<p>奇搜博客运行时长:<span id="sitetime" style="color:#096"></span></p>
<script>
    function siteTime(){
        window.setTimeout("siteTime()", 1000);
        var seconds = 1000
        var minutes = seconds * 60
        var hours = minutes * 60
        var days = hours * 24
        var years = days * 365
        var today = new Date()
        var todayYear = today.getFullYear()
        var todayMonth = today.getMonth()
        var todayDate = today.getDate()
        var todayHour = today.getHours()
        var todayMinute = today.getMinutes()
        var todaySecond = today.getSeconds()
        var t1 = Date.UTC(2019,2,29,10,15,45)
        var t2 = Date.UTC(todayYear,todayMonth,todayDate,todayHour,todayMinute,todaySecond)
        var diff = t2-t1
        var diffYears = Math.floor(diff/years)
        var diffDays = Math.floor((diff/days)-diffYears*365)
        var diffHours =Math.floor((diff-(diffYears*365+diffDays)*days)/hours)
        var diffMinutes =Math.floor((diff-(diffYears*365+diffDays)*days-diffHours*hours)/minutes)
        var diffSeconds =Math.floor((diff-(diffYears*365+diffDays)*days-diffHours*hours-diffMinutes*minutes)/seconds)
        document.getElementById("sitetime").innerHTML=""+diffYears+" 年 "+diffDays+" 天 "+diffHours+" 小时 "+diffMinutes+" 分钟 "+diffSeconds+" 秒"
    }
    siteTime()
</script>


image.png

2、显示效果

image.png

作者头像
南宫俊逸创始人

君子好学,自强不息~

上一篇:如何解决Windows 10 专业版,打开Xshell ,提示由于找不到msvcr110.dll......
下一篇:Windows10 20H2 (19042.985) X64_无更新[纯净精简版]

相关推荐

4

发表评论

阿里云2021年 618 年中钜惠活动