php中将时间差转换为字符串提示的实现代码
来源:才华咖 本文已影响6.82K人
来源:才华咖 本文已影响6.82K人
通过传入数据库中存储的文章发表时的UNIX时间戳,来转化为例如 几分钟前,几小时前,几天前 这样的`提示。就和小编一起去了解下吧!
这看起来更加人性化,好吧,上代码
复制代码 代码如下:
<?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)
{
php时间戳的转换函数
PHP如何实现Unicode和Utf-8编码相互转换
PHP提取图像文件并在浏览器上显示的代码
php时间戳与日期的转换
Java字符串反转和Eclipse代码自动提示
php时间戳与日期如何转换
码头的现代诗歌
PHP简单留言本功能的实现代码
在新时代展现新的作为
教你转换PHP字符集
PHP 字符串正则替换函数preg-replace使用说明介绍
php实现无限级分类实现代码
PHP字符集如何转换
PHP 柱形统计图的实现代码
php进度条实现代码
浅谈如何实现在物理教学中的“教”转为“学”
关于MyEclipse代码提示设置包括html和jsp的代码
PHP滚动日志的代码实现
php中空字符串和0之间的关系详解
PHP时间戳使用实例代码「详细版」
PHP中如何实现crontab代码
关于php去除字符串中空字符的常用方法
详解php中空字符串和0之间的关系
php指定长度分割字符串str-split函数如何实现
解析php时间戳与日期的转换