Typecho博客网站底部添加网站已运行时间教程

样式一:

1. 将代码放入 functions.php

一般在主题根目录:网站 /usr/themes/ 主题

修改一下你自己的网站时间

代码语言:javascript
复制
    // 设置时区
    date_default_timezone_set('Asia/Shanghai');
    /**
     * 秒转时间,格式 年 月 日 时 分 秒
     *
     */
    function getBuildTime() {
        // 在下面按格式输入本站创建的时间
        $site_create_time = strtotime('2019-06-23 00:00:00');
        $time = time() - $site_create_time;
        if (is_numeric($time)) {
            $value = array(
                "years" => 0, "days" => 0, "hours" => 0,
                "minutes" => 0, "seconds" => 0,
            );
            if ($time >= 31556926) {
                $value["years"] = floor($time / 31556926);
                $time = ($time % 31556926);
            }
            if ($time >= 86400) {
                $value["days"] = floor($time / 86400);
                $time = ($time % 86400);
            }
            if ($time >= 3600) {
                $value["hours"] = floor($time / 3600);
                $time = ($time % 3600);
            }
            if ($time >= 60) {
                $value["minutes"] = floor($time / 60);
                $time = ($time % 60);
            }
            $value["seconds"] = floor($time);
        echo ''.$value['years'].
        '年'.$value['days'].
        '天'.$value['hours'].
        '小时'.$value['minutes'].
        '分';
    } else {
        echo '';
    }
}</code></pre></div></div><p><strong>2. 修改 footer.php</strong>

在页脚选择合适的位置加入:

代码语言:javascript
复制
<?php getBuildTime(); ?>

样式二:

修改 footer.php 在页脚选择合适的位置加入:

代码语言:javascript
复制
    本站已安全运行:

function show_date_time(){
window.setTimeout(&#34;show_date_time()&#34;, 1000);
BirthDay=new Date(&#34;05-06-2016 12:12:24&#34;);//建站日期
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);
momk.innerHTML=daysold+&#34;天&#34;+hrsold+&#34;小时&#34;+minsold+&#34;分&#34;+seconds+&#34;秒&#34; ;
}
show_date_time();


#momk{animation:change 10s infinite;font-weight:800; }
@keyframes change{0%{color:#5cb85c;}25%{color:#556bd8;}50%{color:#e40707;}75%{color:#66e616;}100% {color:#67bd31;}}</code></pre></div></div><h3 id="ad6u1" name="%E6%A0%B7%E5%BC%8F%E4%B8%89%EF%BC%9A">样式三:</h3><p><strong>修改 footer.php 在页脚选择合适的位置加入:</strong></p><div class="rno-markdown-code"><div class="rno-markdown-code-toolbar"><div class="rno-markdown-code-toolbar-info"><div class="rno-markdown-code-toolbar-item is-type"><span class="is-m-hidden">代码语言:</span>javascript</div></div><div class="rno-markdown-code-toolbar-opt"><div class="rno-markdown-code-toolbar-copy"><i class="icon-copy"></i><span class="is-m-hidden">复制</span></div></div></div><div class="developer-code-block"><pre class="prism-token token line-numbers language-javascript"><code class="language-javascript" style="margin-left:0">    function NewDate(str) {
str = str.split(&#39;-&#39;);
var date = new Date();
date.setUTCFullYear(str[0], str[1] - 1, str[2]);
date.setUTCHours(0, 0, 0, 0);
return date;
}
function momxc() {
var birthDay =NewDate(&#34;2016-5-6&#34;);
var today=new Date();
var timeold=today.getTime()-birthDay.getTime();
var sectimeold=timeold/1000
var secondsold=Math.floor(sectimeold);
var msPerDay=24*60*60*1000; var e_daysold=timeold/msPerDay;
var daysold=Math.floor(e_daysold);
var e_hrsold=(daysold-e_daysold)*-24;
var hrsold=Math.floor(e_hrsold);
var e_minsold=(hrsold-e_hrsold)*-60;
var minsold=Math.floor((hrsold-e_hrsold)*-60); var seconds=Math.floor((minsold-e_minsold)*-60).toString();
document.getElementById(&#34;momk&#34;).innerHTML = &#34;本站已安全运行&#34;+daysold+&#34;天&#34;+hrsold+&#34;小时&#34;+minsold+&#34;分&#34;+seconds+&#34;秒&#34;;
setTimeout(momxc, 1000);
}momxc();
  
#momk{animation:change 10s infinite;font-weight:800; }
@keyframes change{0%{color:#5cb85c;}25%{color:#556bd8;}50%{color:#e40707;}75%{color:#66e616;}100% {color:#67bd31;}}</code></pre></div></div>