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

2023-03-22 14:18:14 浏览数 (2)

样式一:

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 '';
        }
    }

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

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

样式二:

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

代码语言:javascript复制
    本站已安全运行:
    
    
    function show_date_time(){
    window.setTimeout("show_date_time()", 1000);
    BirthDay=new Date("05-06-2016 12:12:24");//建站日期
    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 "天" hrsold "小时" minsold "分" seconds "秒" ;
    }
    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;}}

样式三:

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

代码语言:javascript复制
    function NewDate(str) {
    str = str.split('-');
    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("2016-5-6");
    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("momk").innerHTML = "本站已安全运行" daysold "天" hrsold "小时" minsold "分" seconds "秒";
    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;}}

0 人点赞