我有一个从MySQL返回的记录,它有一个datetime字段。我想要做的是获取这个值,看看它是否早于24小时,我假设使用PHP的time()来获取当前时间。
现在,如果我把它们说出来,我会得到:
1276954824 this is php's time()
2010-06-19 09:39:23 this is the MySQL datetime我假设最上面的是unix时间?一直在尝试strtotime,但收效甚微..
欢迎使用ANy帮助!
发布于 2010-06-19 21:53:10
没有成功吗?
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
}https://stackoverflow.com/questions/3075698
复制相似问题