php實現網站運行時間

代碼:php

 1 <?php
 2 // 設置時區
 3 date_default_timezone_set('Asia/Shanghai');
 4 /**
 5  * 秒轉時間,格式 年 月 日 時 分 秒
 6  */
 7 function getBuildTime(){
 8     // 在下面按格式輸入本站建立的時間
 9     $site_create_time = strtotime('2020-03-07 22:15:00');
10     $time = time() - $site_create_time;
11     if(is_numeric($time)){
12         $value = array(
13             "years" => 0, "days" => 0, "hours" => 0,
14             "minutes" => 0, "seconds" => 0,
15         );
16         if($time >= 31556926){
17             $value["years"] = floor($time/31556926);
18             $time = ($time%31556926);
19         }
20         if($time >= 86400){
21             $value["days"] = floor($time/86400);
22             $time = ($time%86400);
23         }
24         if($time >= 3600){
25             $value["hours"] = floor($time/3600);
26             $time = ($time%3600);
27         }
28         if($time >= 60){
29             $value["minutes"] = floor($time/60);
30             $time = ($time%60);
31         }
32         $value["seconds"] = floor($time);
33         
34         echo '404發芽'.$value['years'].'年'.$value['days'].'天'.$value['hours'].'小時'.$value['minutes'].'分';
35     }else{
36         echo '';
37     } 

 

調用方法:wordpress

已在風雨中度過:<?php getBuildTime(); ?>
  •  注:wordpress搭建的博客放在:footer.php中
相關文章
相關標籤/搜索