博客统计代码中的动态运行天数

前端之家收集整理的这篇文章主要介绍了博客统计代码中的动态运行天数前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

版本一:PHP

  1.  0, "days" => 0, "hours" => 0,
  2.  "minutes" => 0, "seconds" => 0,
  3.  );
  4.  if($time >= 31556926){
  5.  $value["years"] = floor($time/31556926);
  6.  $time = ($time%31556926);
  7.  }
  8.  if($time >= 86400){
  9.  $value["days"] = floor($time/86400);
  10.  $time = ($time%86400);
  11.  }
  12.  if($time >= 3600){
  13.  $value["hours"] = floor($time/3600);
  14.  $time = ($time%3600);
  15.  }
  16.  if($time >= 60){
  17.  $value["minutes"] = floor($time/60);
  18.  $time = ($time%60);
  19.  }
  20.  $value["seconds"] = floor($time);
  21.  return (array) $value;
  22.  }else{
  23.  return (bool) FALSE;
  24.  }}// 本站创建的时间$site_create_time = strtotime('2017-09-01 00:00:00');$time = time() - $site_create_time;$uptime = Sec2Time($time);?>本站运行:小时

将本站运行以前的代码放到网站的footer中,然后将最后一行代码插入统计代码当中或网站合适的位置即可

版本二:js

  1.  function setTime() {
  2.  // 博客创建时间秒数,时间格式中,月比较特殊,是从0开始的,所以想要显示5月,得写4才行,如下
  3.  var create_time = Math.round(new Date(Date.UTC(2017, 10, 01, 0, 0, 0))
  4.  .getTime() / 1000);
  5.  // 当前时间秒数,增加时区的差异
  6.  var timestamp = Math.round((new Date().getTime() + 8 * 60 * 60 * 1000) / 1000);
  7.  currentTime = secondToDate((timestamp - create_time));
  8.  currentTimeHtml = currentTime[0] + '年' + currentTime[1] + '天'
  9.  + currentTime[2] + '时' + currentTime[3] + '分' + currentTime[4]
  10.  + '秒';
  11.  document.getElementById("htmer_time").innerHTML = currentTimeHtml;
  12.  }
  13.  setInterval(setTime, 1000);
  14.  网站运行:

将网站运行以前的代码放到网站的footer中,然后将最后一行代码插入统计代码当中或网站合适的位置即可

猜你在找的wordpress相关文章