This article will introduce how to implement time conversion based on the timeline.
First we need to understand several functions of time:
time(): Returns the current Unix timestamp
date(): Format a local time/date.
Application example:
Copy code The code is as follows:
date("Y-m-d H:i:s",time()); //Format the current time, output: 2011-9-24 07: 27:35
Copy the code The code is as follows:
echo strtotime("+1 day"), "n"; //Output the timestamp 1 day ago: 1316932222
Copy the 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.'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 the code The code is as follows:
$times="1316932222";
echo tranTime($times);
The above introduces the qq space time axis PHP implementation of the timeline function code, including the content of the qq space time axis. I hope it will be helpful to friends who are interested in PHP tutorials.