PHP显⽰⽹站运⾏时间,php⽹站运⾏时间显⽰代码
php实现显⽰⽹站运⾏时间,需要的朋友可以参考下,假设你的当前时间为这种格式“2017-01-01”,想计算⼏天后时间格式,可⽤的计算代码如下:本站运⾏:<?php echo floor((time()-strtotime('2017-01-01'))/86400);?>本站运⾏:1704天
如果你想计算多少年多少⽉多少⽇可⽤下⾯代码实现:<?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('2017-01-01');
$time = time() - $site_create_time;
$sltime = Sec2Time($time);
echo '本站运⾏:';if($sltime['y']!='0'){echo $sltime['y'].'年';}if($sltime['m']=='0' && $sltime['d']=='0'){echophp如何运行代码
'整';}if($sltime['m']!='0')本站运⾏:4年8⽉3天
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论