//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; $tomorrow = date('Y-m-d',strtotime("2018-03-29 + 1 day"));// 2018-03-29 加一天的日期 echo $tomorrow; // 2018-03-30
也可以這樣
date("Y-m-d",strtotime("-1 day"));//直接獲得前一天時間
當為1月時用此方法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";
聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com