Home  >  Article  >  Backend Development  >  Timeline development in PHP, that is, displayed as "just now", "5 minutes ago", "yesterday 10:23_PHP Tutorial

Timeline development in PHP, that is, displayed as "just now", "5 minutes ago", "yesterday 10:23_PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 17:49:27854browse

//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);


Excerpted from Shunzi Network PHP website construction

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478351.htmlTechArticle//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 now; } elseif ($time 60 *...
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