php代码显示网站运行时间,两个方案任选

php代码源码显示网站运行时间,两种显示方式,需要的朋友自行选择显示格式添加对应代码。代码添加到自己想添加的位置。

一、假如现在的时间为“2019-09-01”,显示效果为多少天:

本站勉强运行:<?php echo floor((time()-strtotime('2019-09-01'))/86400);?>

输出格式:

本站勉强运行:7天

二、假如现在的时间为“2019-09-01”,显示效果为多少年多少月多少日:

<?php
date_default_timezone_set('Asia/Shanghai');
function Sec2Time($time){if(is_numeric($time)){$value = array("y"=>0,"m" =>0,"d" =>0,"h" =>0,"i" =>0,"s" =>0,);
if($time>=31556926){$value["y"] = floor($time/31556926);$time=($time%31556926);}
if($time>=2592000){$value["m"]=floor($time/2592000);$time=($time%2592000);}
if($time>=86400){$value["d"]=floor($time/86400);$time=($time%86400);}
if($time>=3600){$value["h"]=floor($time/3600);$time = ($time%3600);}
if($time>=60){$value["i"] = floor($time/60);$time = ($time%60);}
$value["seconds"]=floor($time);return (array) $value;}else{return (bool) FALSE;}}
$site_create_time = strtotime('2019-09-01');
$time = time() - $site_create_time;
$sltime = Sec2Time($time);
echo '本站勉强运行:';if($sltime['y']!='0'){echo $sltime['y'].'年';}if($sltime['m']=='0' && $sltime['d']=='0'){echo '整';}if($sltime['m']!='0'){echo $sltime['m'].'月';}else{if($sltime['d']!='0'){echo '零';}}if($sltime['d']!='0'){echo $sltime['d'].'天';}?>

本站勉强运行:0年0月7天

注:$site_create_time = strtotime(‘2019-09-01’);此处时间修改为自己想要的时间。

转载请注明出处,如有侵权请联系我删除。如有资源链接失效请给我写信
角落吧 » php代码显示网站运行时间,两个方案任选

发表评论