在用户更新我的MySQL数据库中的帐户后,我如何识别时间?我的MySQL表中有一个时间戳(用于存储用户更新时间),所以现在如何使用PHP识别上次用户更新所传递的时间?
例如:
用户最后更新时间: 2012-04-08 00:20:00; 现在: 2012-04-08 : 00:40:00; 上一次更新后的时间: 20 (分钟)←我需要使用PHP
发布于 2012-04-08 04:18:26
如果你有数据
$last_update_time = '2012-04-08 00:20:00';
$now = time(); //this gets you the seconds since epoch你可以做到
$last_update_since_epoch = strtotime($last_update_time); //this converts the string to the seconds since epoch阿和..。现在,因为这两个变量都有秒
$seconds_passed = $now - $last_update_since_epoch;现在,您可以执行$seconds_passed / 60来获得自上次更新以来的分钟数。
希望这会有所帮助;)
发布于 2012-04-08 04:18:22
在伪码中:
$get_user_time = mysql_query("SELECT timestamp FROM table");
$row = mysql_fetch_array($get_user_time);
$user_time = $row['timestamp']; //This is the last update time for the user
$now_unformatted = date('m/d/Y h:i:s a', time());
$now = date("m/d/y g:i A", $now_unformatted); // This is the current time
$difference = $now->diff($user_time); // This is the difference
echo $difference;PHP5.3支持迪夫()。否则你可以这样做:
$difference = time() - $user_time;发布于 2012-04-08 04:17:23
$secs=time()-strtotime($timestamp);在更新前给出你的秒数,然后你就可以把这个秒转换成你所需要的时间格式,比如echo $secs/60." minutes ago";。
https://stackoverflow.com/questions/10060271
复制相似问题