dongyou1926 2018-03-28 02:45
浏览 85
已采纳

PHP - 如何将文件修改日期与当前日期进行比较

I want to compare the file modification date with the current date.

I tried the following (which is working for the current Time):

$currentDay = date("d");
$currentMonth = date("m");
$currentYear = date("y");
$currentHour = date("h");
$currentMinute = date("i");

Now i tried to get the file modification year from my file:

$subst1 = file("f1/subst_001.htm");
$mod_date=date("y", filemtime($subst1));
echo $mod_date;

But it's giving me for year "70", which is coming from the Year 1970, what did i do wrong?

And no, i already checked if the file says this creation year...

  • 写回答

4条回答 默认 最新

  • doupin8555 2018-03-28 02:52
    关注

    The filetime() function expects string as file path. Here you are trying to pass an array that is returned from file()

    Try like this way,

    $filename= "f1/subst_001.htm";
    if (file_exists($filename)) {
       $mod_date = date("y", filemtime($filename));
       echo $mod_date;
    }
    

    January 1, 1970 is the so called Unix epoch. It's the date where they started counting the Unix time. If you get this date as a return value, it usually means that the conversion of your date to the Unix timestamp returned a (near-) zero result. So the date conversion doesn't succeed. Most likely because it receives a wrong input.

    Courtesy : Oldskool

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch