如何在PHP中计算MySQL时间戳和当前时间之间的差异
答
正如@RemoteSojourner所提到的,我使用UNIX时间戳格式(返回时间以秒为单位)获得当前时间,我从数据库中获得时间戳(使用ORM)并将其转换为UNIX timstamp,然后减去两个时间戳。
$current_time = strtotime("now");
$last_access_time = strtotime($this->last_access);
$inactivity_duration = $current_time - $last_access_time;
答
从MySQL检索日期时间像这样
SELECT UNIX_TIMESTAMP(`time_col`) FROM `tablename`...
,并将其与time()
+0
啊,我假设(来自php + zend标签),你想在PHP比较 – 2011-04-15 11:56:32
答
可以使用将时间戳解析为Unix时间戳的strtotime函数可以在PHP日期函数中进一步解析或格式化。
-1:之后我们已经在聊天中告诉过您要尝试什么并将您链接到http://stackoverflow.com/search?q=[php]+calculate+timestamp+difference和http:// dev.mysql.com/doc/refman/5.5/en/datetime.html你不应该有任何需要问你自己的问题。 – Gordon 2011-04-15 11:56:51
目前还不清楚您的意思是时间戳或unix_timestamp。 – 2011-04-15 11:56:52
为什么这个标签为Zend-Framework? – Tjorriemorrie 2011-04-17 14:03:17