php教程判斷檔修改時間與日期函數
此腳本時,頁面最後修訂和產出作為二十分鐘前,或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); < br>
}
}
//Display It
print("Last Modified: ");
print($returndate);
}
?>
它應該很容易理解。
$ last_modified = filemtime(「FILE.php」); - 更改FILE.php到檔您要連接。