This looks more humane, okay, on the code
Copy CodeThe code is as follows:
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 <) {//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
*/
}
?>
http://www.bkjia.com/PHPjc/324289.html www.bkjia.com true http://www.bkjia.com/PHPjc/324289.html techarticle this looks more humane, OK, the code copy code is as follows: PHP class Timeago {static $timeagoObject; private $rustle; private $unit; Private functi On __construct ( ...