一聚教程网:一个值得你收藏的教程网站

热门教程

php 判断文件修改时间与日期函数

时间:2022-11-14 23:01:47 编辑:袖梨 来源:一聚教程网

此脚本时,页面最后修订和产出作为二十分钟前,或XX天前的日期...或者即使您不更新太多 - 二十周前显示!

//File Name
$last_modified = filemtime("FILE.php");

{
$timediff = time() - $last_modified;

if ($timediff < 3600)
{
if ($timediff < 120)
{
$returndate = "1 minute ago.";
}
else
{
$returndate = intval($timediff / 60) . " minutes ago.";
}
}
else if ($timediff < 7200)
{
$returndate = "1 hour ago.";
}
else if ($timediff < 86400)
{
$returndate = intval($timediff / 3600) . " hours ago.";
}
else if ($timediff < 172800)
{
$returndate = "1 day ago.";
}
else if ($timediff < 604800)
{
$returndate = intval($timediff / 86400) . " days ago.";
}

else if ($timediff < 1209600)
{
$returndate = "1 week ago.";
}
else if ($timediff < 3024000)
{
$returndate = intval($timediff / 604900) . " weeks ago.";
}
else
{
$returndate = @date('n-j-Y', $timestamp);
if($type=="fulldate")
{
$returndate = @date('n-j-y, H:i', $timestamp);

}

else if ($type=="time")
{

$returndate = @date('H:i', $timestamp);

}

}
//Display It
print("Last Modified: ");
print($returndate);

}
?>

它应该很容易理解。

$ last_modified = filemtime(“FILE.php”); - 更改FILE.php到文件您要连接。

热门栏目