戸惑うstrtotime
4542 ワード
strtotime -1 month, +1 month, next month , , . …
, :
2018-07-31 :
date("Y-m-d",strtotime("-1 month"))
2018-07-01?
, , , ” ” , , :
date :
論理が「はっきりしている」のではないでしょうか.2つ目のステップを手動で検証することもできます.たとえば、次のようにします.
var_dump(date("Y-m-d", strtotime("2017-06-31")));
// 2017-07-01
, , , , :
var_dump(date("Y-m-d", strtotime("-1 month", strtotime("2017-03-31"))));
// 2017-03-03
var_dump(date("Y-m-d", strtotime("+1 month", strtotime("2017-08-31"))));
// 2017-10-01
var_dump(date("Y-m-d", strtotime("next month", strtotime("2017-01-31"))));
// 2017-03-03
var_dump(date("Y-m-d", strtotime("last month", strtotime("2017-03-31"))));
// 2017-03-03
?
PHP5.3 , date , , ”first day of” “last day of”, date ” ”:
var_dump(date("Y-m-d", strtotime("last day of -1 month", strtotime("2017-03-31"))));
// 2017-02-28
var_dump(date("Y-m-d", strtotime("first day of +1 month", strtotime("2017-08-31"))));
//// 2017-09-01
var_dump(date("Y-m-d", strtotime("first day of next month", strtotime("2017-01-31"))));
//// 2017-02-01
var_dump(date("Y-m-d", strtotime("last day of last month", strtotime("2017-03-31"))));
//// 2017-02-28
5.3 ( ?), mktime , , 1 , first day .
, , ? ��