如微博
這看起來比較人性化,好吧,上碼
程式碼如下:
class timeAgo
{
static $timeagoObject;
私人$沙沙;
私人$單位;
私有函數__construct()
{
;
{
if(! (self::$timeagoObject instanceof self) )
self::$timeagoObject =新的時間();
回傳self::$timeago主函數
{
if(! (isset($unix_C) || is_numeric($unix_C)) )
return '找不到參數';
$d = time()-$unix_CC // $d - unixix ;時間差值
$d_int =(int)floor($d/60) ; // 最小單位-- 分鐘unix/60
$this->unit = 0 ; // 是分鐘、小時還是天?
if($d_int $this->rustle = $d_int;
$this->unit = 1;
}
else if($d_int $this->rustle = Floor($d_int/60);
$this->unit = 2 ;
}
else if($d_int $this->rustle = Floor($d_int/720);
$this->unit = 3 ;
}
else{
$this->沙聲= $dthis ;
else{
$this->沙聲= $dthis ;
else{
$this->沙聲= $dthis ; >unit = 4 ;
}
}
公共函數piece_str($C)
{
$this->count_int($C);
$u = '';
itch(this-g狀況1:
$u = '分鐘';
休息;
狀況2:
$u = '小時';
休息;
狀況3:
$u = '天';
休息;
狀況3:
$u = '天';
休息; u = '';
休息;
case 0:
return '抱歉,取得時間失敗';
}
if($this->unit {
if($this->otle > 1)
{
if($this-o>tle > 1) (string)$this->rustle.$u.';
else if($this->rustle == 1)
return (string)$this->rustle.$u.'ago';
else
return ' Just now';
}
}
/* 例:$ago = timeAgo::getObject();
* echo $ago->piece_str($unix);
* // 2 天前
*/
*/
*? >