老实说,我不知道如何解释这一点,所以如果你查看http://www.gw2lfg.com,经过时间列是我想要做的,确定某件事是否是一分钟前,两分钟前,等感谢所有的帮助
问问题
147 次
2 回答
0
您正在寻找时间流逝,您可以执行以下操作。
UNIX_TIMESTAMP('2012-12-01 12:12:12') - UNIX_TIMESTAMP(CURTIME());
然后,您可以将其转换为秒和分钟。
于 2013-07-01T05:46:07.127 回答
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
于 2013-07-01T05:52:49.710 回答