我有一条从 MySQL 返回的记录,它有一个日期时间字段。我想做的是获取这个值,看看它是否早于 24 小时,我假设使用 PHP 的 time() 来获取当前时间。
目前,如果我回显它们,我会得到:
1276954824 this is php's time()
2010-06-19 09:39:23 this is the MySQL datetime
我假设最上面的是 unix 时间?一直在玩 strtotime 但收效甚微..
欢迎任何帮助!
最佳答案
没有成功?
echo strtotime("2010-06-19 09:39:23");
给我
1276940363
(mktime(9, 39, 23, 6, 19, 2010)
给出相同的时间,因此解析工作正常)
要获得以秒为单位的差异,您可以减去时间戳,例如
$diff = time() - strtotime("2010-06-19 09:39:23");
如果差异大于 86400 (60*60*24) 秒,则时间戳相隔超过一天:
if(time() - strtotime("2010-06-19 09:39:23") > 60*60*24) {
// timestamp is older than one day
}
关于php - 从 php now() 检查 mySql 日期时间是否早于 1 天,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3075698/