在平時的業務邏輯中常常會遇到用strtotime('last month')或strtotime('-1 month') 獲取上一個月,ast
strtotime('next month')或strtotime('+1 month') 獲取下一個月date
可是在月末,若是先後兩個月的天數不同多,用strtotime獲取上一月的時候就得不到理想的值im
好比:在10月31日,獲取上月就是錯誤的(獲得的結果是10月)next
一樣:在10月31日,獲取下個月也是錯誤的(獲得的結果是12月)time
在月初用strtotime存在一樣的問題錯誤
在求上一個月或下一個月的時候,能夠用 mktime(0, 0, 0, date('m')-1,date('d'), date('Y'))
或mktime(0, 0, 0,date('m')+1, date('d'), date('Y'))