親測直接使用 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"));
if(!strcmp($type,'l'))
. date("Y-m-d H:i:s",strtotime("+$Minu minute"));
return $res;
}
//間隔幾秒之前或之後的時間點
func GetSec($sec,$type='l')
{
if(!strcmp($type,'b'))
$res=date("Y-m-d H:i:s",strtotime("-$sec second "));
if(!strcmp($type,'l'))
$res=date("Y-m-d H:i:s",strtotime("+$sec second") );
return $res;
}