php将时间差转换为字符串提示
2015-01-24信息快讯网
<?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
*/
}
?>
php笔记之:php函数range() round()和list()的使用说明
input file获得文件根目录简单实现
PHP中操作ini配置文件的方法
php class中self,parent,this的区别以及实例介绍
PHP中::、->、self、$this几种操作符的区别介绍
基于magic_quotes_gpc与magic_quotes_runtime的区别与使用介绍
基于initPHP的框架介绍
关于PHP的相似度计算函数:levenshtein的使用介绍
phpmyadmin显示utf8_general_ci中文乱码的问题终级篇
PHP-redis中文文档介绍
php中使用redis队列操作实例代码
PDO版本问题 Invalid parameter number: no parameters were bound
php中unlink()、mkdir()、rmdir()等方法的使用介绍
PHP提示Notice: Undefined variable的解决办法
PHP 中关于ord($str)>0x80的详细说明
使用PHP实现密保卡功能实现代码<打包下载直接运行>
php中实现简单的ACL 完结篇
php 中英文语言转换类
PHP表单验证的3个函数ISSET()、empty()、is_numeric()的使用方法
phpmyadmin安装时提示:Warning: require_once(./libraries/common.inc.php)错误解决办法
PHP中获取内网用户MAC地址(WINDOWS/linux)的实现代码
ThinkPHP 防止表单重复提交的方法
ThinkPHP与PHPExcel冲突解决方法
让Nginx支持ThinkPHP的URL重写和PATHINFO的方法分享
discuz程序的PHP加密函数原理分析
PHP源代码数组统计count分析
PHP 删除文件与文件夹操作 unlink()与rmdir()这两个函数的使用
PHP Undefined index报错的修复方法
php自定义函数call_user_func和call_user_func_array详解
PHP array_multisort()函数的使用札记
php设计模式 Visitor 访问者模式
从康盛产品(discuz)提取出来的模板类
Warning: session_destroy() : Trying to destroy uninitialized sessionq错误
php中$this->含义分析
php self,$this,const,static,->的使用
PHP nl2br函数 将换行字符转成 <br>