老实说,我不知道如何解释这个,所以如果你看一下http://www.gw2lfg.com,经过时间的栏目就是我要做的,确定一些东西是一分钟,两分钟,等等感谢所有的帮助
答案 0 :(得分:0)
您正在寻找时间,您可以执行以下操作。
UNIX_TIMESTAMP('2012-12-01 12:12:12') - UNIX_TIMESTAMP(CURTIME());
然后您可以将其转换为秒和分钟。
答案 1 :(得分:0)
试试这个工作示例,
function time_ago($date)
{
if (empty($date)) { // $date=> mysql timestatmp
return "No date provided";
}
$periods = array("sec", "min", "hr", "day", "week", "month", "year", "decade");
$lengths = array("60","60","24","7");
$now = time();
$unix_date = strtotime($date);
// check validity of date
if (empty($unix_date)) {
return "Bad date";
}
// is it future date or past date
if ($now >= $unix_date) {
$difference = $now - $unix_date;
$tense = "ago";
} else {
$difference = $unix_date - $now;
$tense = "from now";
}
for ($j = 0; $difference >= $lengths[$j] && $j < count($lengths)-1; $j++) {
$difference /= $lengths[$j];
}
$difference = round($difference);
if ($difference != 1 && $j != 0) {
$periods[$j].= "s";
}
if($difference!=0)
return "$difference $periods[$j] {$tense}";
else
return "a few seconds ago";
}
<强>更新强>
用法:
echo time_ago('2013-07-01 11:30:00'); // Output: 5 mins ago