如微博
这看起来更加人性化,好吧,上代码
代码如下:
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 $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->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 {
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
*/
}
?>
0
0
相关文章
如何从 XML 中提取多个同名节点并构建成数组
php数组如何筛选非ASCII字符_php非ASCII数组筛选法【技巧】
php怎样检测变量是PDO对象_phpPDO实例判断法【方法】
php按制表符分割文本怎么写_php制表符分割文本preg_split【技巧】
php数组如何筛选特定结构JSON_php结构JSON数组筛选【技巧】
相关标签:
本站声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门AI工具
相关专题
2026赚钱平台入口大全
2026年最新赚钱平台入口汇总,涵盖任务众包、内容创作、电商运营、技能变现等多类正规渠道,助你轻松开启副业增收之路。阅读专题下面的文章了解更多详细内容。
63
2026.01.31
无需付费的漫画app大全
想找真正免费又无套路的漫画App?本合集精选多款永久免费、资源丰富、无广告干扰的优质漫画应用,涵盖国漫、日漫、韩漫及经典老番,满足各类阅读需求。阅读专题下面的文章了解更多详细内容。
67
2026.01.31
漫画免费在线观看地址大全
想找免费又资源丰富的漫画网站?本合集精选2025-2026年热门平台,涵盖国漫、日漫、韩漫等多类型作品,支持高清流畅阅读与离线缓存。阅读专题下面的文章了解更多详细内容。
19
2026.01.31
热门下载
相关下载
精品课程
相关推荐
/
热门推荐
/
最新课程
最新文章







