【问题标题】:PHP: Compare file timestamp with system timePHP:将文件时间戳与系统时间进行比较
【发布时间】:2011-06-20 22:27:02
【问题描述】:

我是 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?

【问题讨论】:

    标签: php timestamp


    【解决方案1】:

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

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

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

    【讨论】:

    • 谢谢。我刚刚想通了那部分。哈哈
    【解决方案2】:

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

    你可以从$timeStamp1得到同样的东西

    $timeStamp1 = strtotime($timeStamp1)

    然后比较两个值

    【讨论】:

      【解决方案3】:

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

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-07-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多