//獲得當前時間
//date()格式化時間返回String類型。 date("Y-m-d H:i:s")
$current_date = date(’Y-m-d’,time());
//根據當前時間加一周后
$weekLater = date(’Y-m-d’,strtotime("$current_date + 1 week"));
echo $weekLate;
// 2009-05-26 加一天的日期
$tomorrow = date(’Y-m-d’,strtotime("2009-05-26 + 1 day"));
echo $tomorrow; // 2009-05-27
也可以這樣 date("Y-m-d",strtotime("-1 day")) ;直接獲得前一天時間
用此方法date(“Y-m-d”, strtotime(“-1 month”))得到上個月的日期時是有問題存在的。問題就出在當前月如果有30,31號時用此方法獲取上月會出錯。比如你在1月30號或1月31號時用此方法得到上月的月份會顯示還是1月份。因此,采用這個函數自動獲取上個月的記錄則出錯。還是笨辦法解決:
if (date("n") == 1) {
$tmpMonth = 12;
$tmpYear = date ("Y") - 1;
}else{
$tmpMonth = date ("n") - 1;
$tmpYear = date ("Y");
}
$tmpDate = "$tmpYear-$tmpMonth-1";