gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 20:27:46 25 4
gpt4 key购买 nike

我想比较文件修改日期和当前日期。

我尝试了以下方法(在当前时间有效):

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

现在我尝试从我的文件中获取文件修改年份:

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

但是它给了我“70”年,这是从 1970 年开始的,我做错了什么?

不,我已经检查过文件是否显示了这个创建年份......

最佳答案

filetime()函数需要 string 作为文件路径。此处您试图传递从 file() 返回的 array

这样试试,

$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.

礼貌:Oldskool

关于PHP - 如何将文件修改日期与当前日期进行比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49525261/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com