php實例分享之實現(xiàn)顯示網(wǎng)站運行時間
廢話不多說,直接上代碼。
<?php
// 設置時區(qū)
date_default_timezone_set('Asia/Shanghai');
/**
* 秒轉時間,格式 年 月 日 時 分 秒
*
* @author wangyupeng129@126.com
* @param int $time
* @return array|boolean
*/
function Sec2Time($time){
if(is_numeric($time)){
$value = array(
"years" => 0, "days" => 0, "hours" => 0,
"minutes" => 0, "seconds" => 0,
);
if($time >= 31556926){
$value["years"] = floor($time/31556926);
$time = ($time%31556926);
}
if($time >= 86400){
$value["days"] = floor($time/86400);
$time = ($time%86400);
}
if($time >= 3600){
$value["hours"] = floor($time/3600);
$time = ($time%3600);
}
if($time >= 60){
$value["minutes"] = floor($time/60);
$time = ($time%60);
}
$value["seconds"] = floor($time);
return (array) $value;
}else{
return (bool) FALSE;
}
}
// 本站創(chuàng)建的時間
$site_create_time = strtotime('2013-05-22 00:00:00');
$time = time() - $site_create_time;
$uptime = Sec2Time($time);
?>
本站運行:<span style="color:red;"><?php echo $uptime['years']; ?>年<?php echo $uptime['days']; ?>天<?php echo $uptime['hours']; ?>小時<?php echo $uptime['minutes']; ?>分<?php echo $uptime['seconds']; ?>秒</span>
相關文章
Javarscript中模塊(module)、加載(load)與捆綁(bundle)詳解
這篇文章主要給大家介紹了關于Javarscript中模塊(module)、加載(load)與捆綁(bundle)的相關資料,文中介紹的非常詳細,對大家具有一定的參考學習價值,需要的朋友們下面跟著小編一起來學習學習吧。2017-05-05
微信小程序ajax實現(xiàn)請求服務器數(shù)據(jù)及模版遍歷數(shù)據(jù)功能示例
這篇文章主要介紹了微信小程序ajax實現(xiàn)請求服務器數(shù)據(jù)及模版遍歷數(shù)據(jù)功能,結合實例形式分析了微信小程序ajax調(diào)用及模板wx:for循環(huán)列表渲染相關操作技巧,需要的朋友可以參考下2017-12-12
用JavaScript實現(xiàn)UrlEncode和UrlDecode的腳本代碼
用js自定義函數(shù)寫的實現(xiàn)url加密解密的實現(xiàn)代碼,需要的朋友可以參考下2008-07-07

