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');此处时间修改为自己想要的时间。

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。