2011-06-20 60 views
3

我是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脚本。我目前使用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?

回答

4

也就是说Unix时间戳实际上(秒自1970年1月1日或纪元)

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

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

+0

谢谢。我只是想到了这一点。哈哈 –

+0

很高兴知道。当你有机会时不要忘记标记这个答案为接受:) – anubhava

1

$timeStamp2是UNIX时间戳记(自01/01/1970以来经过的秒数)。

您可以通过执行

$timeStamp1 = strtotime($timeStamp1)

得到$timeStamp1同样的事情,然后比较这两个值

0

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

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