


Timeline development in PHP, that is, displayed as 'just now', '5 minutes ago', 'yesterday 10:23'_PHP Tutorial
Jul 13, 2016 pm 05:46 PM
//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

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

How To Set Up Visual Studio Code (VS Code) for PHP Development
