最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

php將時(shí)間差轉(zhuǎn)換為字符串提示

 更新時(shí)間:2011年09月07日 00:45:08   作者:  
通過傳入數(shù)據(jù)庫中存儲(chǔ)的文章發(fā)表時(shí)的UNIX時(shí)間戳,來轉(zhuǎn)化為例如 幾分鐘前,幾小時(shí)前,幾天前 這樣的提示。如微博
這看起來更加人性化,好吧,上代碼
復(fù)制代碼 代碼如下:

<?php
class timeAgo
{
static $timeagoObject;
private $rustle;
private $unit;
private function __construct()
{
}
private function __clone(){ }
public static function getObject()
{
if(! (self::$timeagoObject instanceof self) )
self::$timeagoObject = new timeAgo();
return self::$timeagoObject;
}
private function count_int($unix_C) // main function
{
if(! (isset($unix_C) || is_numeric($unix_C)) )
return 'don\'t find parameter';
$d = time()-$unix_C ; // $d - unix time difference value
$d_int =(int)floor($d/60) ; // minimum unit -- minutes unix/60
$this->unit = 0 ; // is minutes,hour or day?
if($d_int < 60){ // minutes in one hour 3600
$this->rustle = $d_int;
$this->unit = 1;
}
else if($d_int < 720){ //hour in one day 3600*12
$this->rustle = floor($d_int/60);
$this->unit = 2 ;
}
else if($d_int < 7200){ //day in ten days 3600*12*10
$this->rustle = floor($d_int/720);
$this->unit = 3 ;
}
else{
$this->rustle = $d ;
$this->unit = 4 ;
}
}
public function piece_str($C)
{
$this->count_int($C);
$u = '';
switch( $this->unit )
{
case 1:
$u = 'minute';
break;
case 2:
$u = 'hour';
break;
case 3:
$u = 'day';
break;
case 4:
$u = '';
break;
case 0:
return 'sorry , get time is fail';
}
if($this->unit < 4)
{
if($this->rustle > 1)
return (string)$this->rustle.$u.'s ago';
else if($this->rustle == 1)
return (string)$this->rustle.$u.'ago';
else
return 'Just now';
}
}
/* example: $ago = timeAgo::getObject();
* echo $ago->piece_str($unix);
* // 2 days ago
*/
}
?>

相關(guān)文章

最新評(píng)論

黑水县| 砚山县| 清涧县| 南阳市| 镶黄旗| 庆元县| 翁牛特旗| 合作市| 灵台县| 泗洪县| 洮南市| 弥勒县| 黔南| 新密市| 靖西县| 冀州市| 福泉市| 四子王旗| 疏勒县| 孙吴县| 宜昌市| 祥云县| 平山县| 介休市| 辽源市| 土默特左旗| 平乐县| 云和县| 新河县| 宝兴县| 凌云县| 分宜县| 周宁县| 渑池县| 龙州县| 鹿邑县| 江孜县| 乐亭县| 西贡区| 枣阳市| 鹤岗市|