親測直接使用 strtotime("-1 day");
顯示的是今日的前一日也就是昨日。今日是根據當前的Unix時間截來斷定的。
date_default_timezone_set('PRC'); //預設時區
echo "今天:",date("Y-m-d",time()),"
";
echo "今天:",date("Y-m-d",strtotime("18 june 2008")),"
";
echo "昨天:",date("Y-m-d",strtotime("-1 day")), "
";
echo "明天:",date("Y-m-d",strtotime("+1 day")), "
";
echo "一周后:",date("Y-m-d",strtotime("+1 week")), "
";
echo "一周零兩天四小時兩秒後:",date("Y-m-d G:H:s",strtotime("+1 week 2 days 4 hours 2 seconds")), "
";
echo "下個星期四:",date("Y-m-d",strtotime("next Thursday")), "
";
echo "上個周一:".date("Y-m-d",strtotime("last Monday"))."
";
echo "一個月前:".date("Y-m-d",strtotime("last month"))."
";
echo "一個月後:".date("Y-m-d",strtotime("+1 month"))."
";
echo "十年後:".date("Y-m-d",strtotime("+10 year"))."
";
?>
//間隔幾分鐘之前或之後的時間
function GetMinute($Minu,$type='l')
{
if(!strcmp($type,'b'))
$res=date("Y-m-d H:i:s",strtotime("-$Minu minute"));
else $res=0;
if(!strcmp($type,'l'))
$res=date("Y-m-d H:i:s",strtotime("+$Minu minute"));
else $res=0;
return $res;
}
//間隔幾秒之前或之後的時間
function GetSec($sec,$type='l')
{
if(!strcmp($type,'b'))
$res=date("Y-m-d H:i:s",strtotime("-$sec second"));
else $res=0;
if(!strcmp($type,'l'))
$res=date("Y-m-d H:i:s",strtotime("+$sec second"));
else $res=0;
return $res;
}
以上就介紹了php輸出時間差,包括了方面的內容,希望對PHP教程有興趣的朋友有所協助。