ecshop二次开发--添加普通时间显示

1.进入include->lib_insert.php中复制代码添加一个方法

include目录:ecshop中的一些公用函数都会放在includes文件夹里,而这些公用函数几乎我们都可以用来参照一下就能轻松做出我们想要的其他功能了。

function insert_now_time(){
 $str="<span id='nowTime'></span>
<script type='text/javascript' language='javascript'>
    
    var c = 0;
    var Y = ".date('Y').", M = ".date('n').", D =".date('j').";
    function stime() {
        c++
        sec = ".(time() - strtotime(date('Y-m-d')))."+c;
        H = Math.floor(sec / 3600) % 24
        I = Math.floor(sec / 60) % 60
        S = sec % 60
        if (S < 10) S = '0' + S;
        if (I < 10) I = '0' + I;
        if (H < 10) H = '0' + H;
        if (H == '00' & I == '00' & S == '00') D = D + 1; //日进位
        if (M == 2) { //判断是否为二月份******
            if (Y % 4 == 0 && !Y % 100 == 0 || Y % 400 == 0) { //是闰年(二月有28天)
                if (D == 30) {
                    M += 1;
                    D = 1;
                } //月份进位
            }
            else { //非闰年(二月有29天)
                if (D == 29) {
                    M += 1;
                    D = 1;
                } //月份进位
            }
        }
        else { //不是二月份的月份******
            if (M == 4 || M == 6 || M == 9 || M == 11) { //小月(30天)
                if (D == 31) {
                    M += 1;
                    D = 1;
                } //月份进位
            }
            else { //大月(31天)
                if (D == 32) {
                    M += 1;
                    D = 1;
                } //月份进位
            }
        }
        if (M == 13) {
            Y += 1;
            M = 1;
        } //年份进位
        setTimeout('stime()', 1000);
        document.getElementById('nowTime').innerHTML = Y + '-' + M + '-' + D + ' ' + H + ':' + I + ':' + S
    }
     stime();
</script>";
 return $str;
}

2.进入theme->default->library->page_header.php中调用前面的那个方法
{insert name='now_time'}

3.案例效果:




你可能感兴趣的:(ecshop二次开发--添加普通时间显示)