WordPress博客添加显示运行时间

代码部署:打开  网站路径/wp-content/themes/主题名/footer.php

网站已运行:<span id="run_time" style="color: red;"></span>
<script>
function runTime() {
    var d = new Date(), str = '';
    BirthDay = new Date("2021-12-01");
    today = new Date();
    timeold = (today.getTime() - BirthDay.getTime());
    sectimeold = timeold / 1000
    secondsold = Math.floor(sectimeold);
    msPerDay = 24 * 60 * 60 * 1000
    msPerYear = 365 * 24 * 60 * 60 * 1000
    e_daysold = timeold / msPerDay
    e_yearsold = timeold / msPerYear
    daysold = Math.floor(e_daysold);
    yearsold = Math.floor(e_yearsold);
    //str = yearsold + "年";
    str += daysold + "天";
    str += d.getHours() + '时';
    str += d.getMinutes() + '分';
    str += d.getSeconds() + '秒';
    return str;
}
setInterval(function () {
    $('#run_time').html(runTime())
}, 1000);
</script>

 

正文完
 0
365share
版权声明:本站原创文章,由 365share 于2021-12-25发表,共计645字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。