我对 php 中的各种日期函数和格式感到非常困惑,所以如果可能的话,我想寻求帮助。
我正在尝试查找在两个日期之间修改的文件,但语法让我感到困惑。例如,如果我尝试查找在 6 个月到 1 年前更改的文件,我尝试过:
$yearago = new DateTime("now");
date_sub($yearago, date_interval_create_from_date_string("1 year"));
$sixmonthsago = new DateTime("now");
date_sub($sixmonthsago, date_interval_create_from_date_string("6 months"));
$dir = '/datacore/';
$files1 = scandir($dir);
foreach($files1 as $key => $value)
{
$datemod = filemtime($value);
if ($datemod>$yearago && $datemod<$sixmonthsago) // eg between 6 and 12 months ago
{
// Do stuff
}
}
我知道这是低效的;在目录中找到一个文件名数组,然后在 filemtime 上循环遍历这个数组,但这是将来要做的事情,但它的日期和 DateTime 的混合让我感到困惑。