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. ' 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;
}
The parameter in function Trantime () must be a Unix timestamp, and if not, convert it to a UNIX timestamp by using Strtotime () first.
Call function, Direct output:
$times = "1286861696";
echo Trantime ($times);
Author: aolinks ' s Blog
http://www.bkjia.com/PHPjc/478605.html www.bkjia.com true http://www.bkjia.com/PHPjc/478605.html techarticle //Time conversion function Trantime ($time) {$rtime = date (m-d h:i, $time); $htime = Date (h:i, $time); $time = times ()-$time; if ($time 60) {$str = just;} ElseIf ($time * ...