Home > Backend Development > PHP Tutorial > Timeline development in php

Timeline development in php

不言
Release: 2023-03-23 20:56:02
Original
2006 people have browsed it

The content shared with you in this article is about the development of timeline in php, which has certain reference value. Friends in need can refer to

Timeline development in php, which is displayed as "just now" , "5 minutes ago", "Yesterday 10:23", etc.

In fact, this has no technical content. Of course, just paste the code directly without any nonsense.
But it is still quite useful in actual development, for example Forum posts, scarves, etc. all have related applications

Copy 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 = &#39;刚刚&#39;; 
} 
elseif ($time < 60 * 60) { 
$min = floor($time/60); 
$str = $min.&#39;分钟前&#39;; 
} 
elseif ($time < 60 * 60 * 24) { 
$h = floor($time/(60*60)); 
$str = $h.&#39;小时前 &#39;.$htime; 
} 
elseif ($time < 60 * 60 * 24 * 3) { 
$d = floor($time/(60*60*24)); 
if($d==1) 
$str = &#39;昨天 &#39;.$rtime; 
else 
$str = &#39;前天 &#39;.$rtime; 
} 
else { 
$str = $rtime; 
} 
return $str; 
}
Copy after login


The parameter $time in the function tranTime() must be Unix timestamp, if not please use strtotime() to convert it to 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 code The code is as follows:

$times="1286861696 "; 
echo tranTime($times);
Copy after login

Related recommendations:

php time How to use stamp

Detailed explanation of PHP timestamp function

PHP timestamp and date conversion example sharing

The above is the detailed content of Timeline development in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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