php实现网站运行时间
程序员文章站
2022-07-09 19:01:13
代码: 1
代码:
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 }
调用方法:
已在风雨中度过:<?php getbuildtime(); ?>
- 注:wordpress搭建的博客放在:footer.php中