开发者

PHP: Compare file timestamp with system time

开发者 https://www.devze.com 2023-03-14 17:43 出处:网络
I am new to PHP and am writing a PHP script that contains 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

I am new to PHP and am writing a PHP script that contains 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. I am currently using

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

The two $timeStamp and $timeStamp2 are different, the 1st one is more human readable

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

What does $timeStamp2开发者_如何学Go mean?

And again, how to see if the file is more than 5 minutes old?


That is Unix timestamp actually (seconds since 1st jan 1970 or EPOCH)

You can use time() function to get current time in same Unix format.

And then subtract both time values to check whether difference is > 300 (5 min) or not.


$timeStamp2 is a UNIX timestamp (the number of seconds passed since 01/01/1970).

You can get the same thing from $timeStamp1 by doing

$timeStamp1 = strtotime($timeStamp1)

and then compare the two values


Answering your question "What does $timeStamp2 mean?"

1308608221 is the number of seconds that have passed since midnight January 1,1970.

0

精彩评论

暂无评论...
验证码 换一张
取 消