-
-
- 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';
- } //Timeline bbs.it-home.org
- elseif ($time < 60 * 60 * 24) {
- $h = floor($time/(60*60));
- $str = $h.'hour 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;
- }
-
Copy code
The parameter $time in function tranTime() must be a Unix timestamp. If not, please use strtotime() first Convert it to Unix timestamp.
Call example:
-
-
- //php timeline function example
- $times="1286861696 ";
- echo tranTime($times);
Copy code
>>> You may be interested article:
Sample code for php to get time and how many minutes ago
Small example of PHP deleting all files created N minutes ago
PHP displays the implementation code just now, a few minutes ago, and a few hours ago according to the time
php implements the function code that posted the information a few minutes ago
|