In fact, this has no technical content. Of course, I just paste the code directly without any nonsense.
But it is still quite useful in development. For example, forum posts, scarves, etc. 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 = '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 function tranTime() must be a Unix timestamp. If not, please use strtotime() first Convert it to Unix timestamp. 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);
http://www.bkjia.com/PHPjc/324391.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/324391.htmlTechArticleActually, this has no technical content. Of course, I just paste the code directly, no nonsense, but it is still quite useful in actual development. Yes, such as forum posts, scarves, etc., there are related application copy codes...
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