PHP:将文件时间戳与系统时间进行比较

时间:2011-06-20 22:27:03

标签: php timestamp

我是PHP的新手,正在编写一个包含a module which reads the file timestamp out of a file and then compare with system time to see whether the file is older than 5 minutes or not and I am wondering how that can be achieved的PHP脚本。我目前正在使用

$timeStamp = strftime('%c', filectime($this->localPath));
$timeStamp2 = filectime($this->localPath);

两个$timeStamp$timeStamp2不同,第一个更具人性化

$timeStamp Mon Jun 20 15:17:01 2011
$timeStamp2 1308608221 

$timeStamp2是什么意思?

再次,如何查看the file is more than 5 minutes old?

3 个答案:

答案 0 :(得分:4)

实际上是 Unix时间戳(自1970年1月1日或EPOCH以来的秒数)

您可以使用time() function以相同的Unix格式获取当前时间。

然后减去两个时间值以检查差异是否> 300(5分钟)或不。

答案 1 :(得分:1)

$timeStamp2是UNIX时间戳(自1970年1月1日起经过的秒数)。

您可以通过

$timeStamp1获得相同的内容

$timeStamp1 = strtotime($timeStamp1)

然后比较两个值

答案 2 :(得分:0)

回答你的问题“$ timeStamp2是什么意思?”

1308608221是自1970年1月1日午夜以来经过的秒数。

相关问题