//Time conversion function
function tranTime($time) {
$rtime = date("m-d H:i",$time);
$htime = date("H:i",$time);
$time = time() - $time;
If ($time < 60) {
$str = 'just';
}
elseif ($time < 60 * 60) {
$min = floor($time/60);
$str = $min.'minutes ago';
}
elseif ($time < 60 * 60 * 24) {
$h = floor($time/(60*60));
$str = $h.'Hours ago'.$htime;
}
elseif ($time < 60 * 60 * 24 * 3) {
$d = floor($time/(60*60*24));
if($d==1)
$str = 'Yesterday'.$rtime;
else
$str = 'The day before yesterday'.$rtime;
}
else {
$str = $rtime;
}
Return $str;
}
The parameter $time in the function tranTime() must be a Unix timestamp. If not, please use strtotime() to convert it to a Unix timestamp first.
Call the function and output directly:
$times="1286861696 ";
echo tranTime($times);