首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何识别用户更新后的时间?

问如何识别用户更新后的时间?
EN

Stack Overflow用户
提问于 2012-04-08 03:58:00
回答 4查看 121关注 0票数 1

在用户更新我的MySQL数据库中的帐户后,我如何识别时间?我的MySQL表中有一个时间戳(用于存储用户更新时间),所以现在如何使用PHP识别上次用户更新所传递的时间?

例如:

用户最后更新时间: 2012-04-08 00:20:00; 现在: 2012-04-08 : 00:40:00; 上一次更新后的时间: 20 (分钟)←我需要使用PHP

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2012-04-08 04:18:26

如果你有数据

代码语言:javascript
复制
$last_update_time = '2012-04-08 00:20:00';
$now = time(); //this gets you the seconds since epoch

你可以做到

代码语言:javascript
复制
$last_update_since_epoch = strtotime($last_update_time); //this converts the string to the seconds since epoch

阿和..。现在,因为这两个变量都有秒

代码语言:javascript
复制
$seconds_passed = $now - $last_update_since_epoch;

现在,您可以执行$seconds_passed / 60来获得自上次更新以来的分钟数。

希望这会有所帮助;)

票数 3
EN

Stack Overflow用户

发布于 2012-04-08 04:18:22

在伪码中:

代码语言:javascript
复制
$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支持迪夫()。否则你可以这样做:

代码语言:javascript
复制
$difference = time() - $user_time;
票数 1
EN

Stack Overflow用户

发布于 2012-04-08 04:17:23

代码语言:javascript
复制
$secs=time()-strtotime($timestamp);

在更新前给出你的秒数,然后你就可以把这个秒转换成你所需要的时间格式,比如echo $secs/60." minutes ago";。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10060271

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档