Home >Backend Development >PHP Tutorial >facebook timeline timeline development in php just now, 5 minutes ago, yesterday 10:23, etc.

facebook timeline timeline development in php just now, 5 minutes ago, yesterday 10:23, etc.

WBOY
WBOYOriginal
2016-07-29 08:46:521305browse

In fact, there is no technical content in this, of course, just paste the code directly, no nonsense,
But it is still quite useful in development, such as forum posts, scarves, etc., there are related applications

Copy the code The code is as follows:


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;
}


function tranTime The parameter $time in () must be a Unix timestamp. If not, please use strtotime() to convert it to a Unix timestamp first. The above code is easy to understand at a glance, so there is no need to elaborate further.
Call the function and output directly:

Copy the code The code is as follows:


$times="1286861696 ";
echo tranTime($times);

The above introduces the timeline development in facebook timeline in php just now, 5 minutes ago, yesterday 10:23, etc., including the content of facebook timeline, I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn