Copy CodeThe code is as follows:
/**
* Friendly Date and time
*
* Date Time @param datetime $datetime
* @param int $size Precise in-place number
* @throws \invalidargumentexception
* @return String
*/
function Friendly_date ($datetime, $size =1)
{
if (Is_int ($datetime)) {
$datetime = new \datetime ($datetime);
}
if (! ( $datetime instanceof \datetime)) {
throw new \invalidargumentexception (' invalid ' DateTime "Object");
}
$now = new \datetime ();
$interval = $now->diff ($datetime);
$intervalData = Array (
$interval->y, $interval->m, $interval->d,
$interval->h, $interval->i, $interval->s,
);
$intervalFormat = Array (' Year ', ' Month ', ' Day ', ' hour ', ' minute ', ' second ');
foreach ($intervalData as $index = = $value) {
if ($value) {
$intervalData [$index] = $value. $intervalFormat [$index];
} else {
Unset ($intervalData [$index]);
Unset ($intervalFormat [$index]);
}
}
Return implode (", Array_slice ($intervalData, 0, $size));
}
http://www.bkjia.com/PHPjc/324421.html www.bkjia.com true http://www.bkjia.com/PHPjc/324421.html techarticle Copy the code code as follows:/** * Friendly Date Time * * @param DateTime $datetime Date time * @param int $size exact number of in place * @throws \invalidargumentexceptio n * @return stri ...