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

WBOY
Release: 2016-07-13 17:46:07
Original
832 people have browsed it

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

Author: aolinks's Blog

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478605.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 *...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template