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

来源:互联网 发布:淘宝11销量排行 编辑:程序博客网 时间:2024/06/13 22:14

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

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

[python] view plain copy 在CODE上查看代码片派生到我的代码片
  1. function insert_now_time(){  
  2.  $str="<span id='nowTime'></span>  
  3. <script type='text/javascript' language='javascript'>  
  4.       
  5.     var c = 0;  
  6.     var Y = ".date('Y').", M = ".date('n').", D =".date('j').";  
  7.     function stime() {  
  8.         c++  
  9.         sec = ".(time() - strtotime(date('Y-m-d')))."+c;  
  10.         H = Math.floor(sec / 3600) % 24  
  11.         I = Math.floor(sec / 60) % 60  
  12.         S = sec % 60  
  13.         if (S < 10) S = '0' + S;  
  14.         if (I < 10) I = '0' + I;  
  15.         if (H < 10) H = '0' + H;  
  16.         if (H == '00' & I == '00' & S == '00') D = D + 1; //日进位  
  17.         if (M == 2) { //判断是否为二月份******  
  18.             if (Y % 4 == 0 && !Y % 100 == 0 || Y % 400 == 0) { //是闰年(二月有28天)  
  19.                 if (D == 30) {  
  20.                     M += 1;  
  21.                     D = 1;  
  22.                 } //月份进位  
  23.             }  
  24.             else { //非闰年(二月有29天)  
  25.                 if (D == 29) {  
  26.                     M += 1;  
  27.                     D = 1;  
  28.                 } //月份进位  
  29.             }  
  30.         }  
  31.         else { //不是二月份的月份******  
  32.             if (M == 4 || M == 6 || M == 9 || M == 11) { //小月(30天)  
  33.                 if (D == 31) {  
  34.                     M += 1;  
  35.                     D = 1;  
  36.                 } //月份进位  
  37.             }  
  38.             else { //大月(31天)  
  39.                 if (D == 32) {  
  40.                     M += 1;  
  41.                     D = 1;  
  42.                 } //月份进位  
  43.             }  
  44.         }  
  45.         if (M == 13) {  
  46.             Y += 1;  
  47.             M = 1;  
  48.         } //年份进位  
  49.         setTimeout('stime()'1000);  
  50.         document.getElementById('nowTime').innerHTML = Y + '-' + M + '-' + D + ' ' + H + ':' + I + ':' + S  
  51.     }  
  52.      stime();  
  53. </script>";  
  54.  return $str;  
  55. }  

2.进入theme->default->library->page_header.php中调用前面的那个方法
[python] view plain copy 在CODE上查看代码片派生到我的代码片
  1. {insert name='now_time'}  

3.案例效果:


0 0
原创粉丝点击