strtotime() 获取 -1 月的第 7 天
strtotime() Get 7th day of -1 month
我试过了:
$firstOfMonth = "2015-01-01";
$last_month = date("Y-m-d", strtotime('first day of -1 month', strtotime($firstOfMonth)));
/* ^^^^^ This gives me 01 of last month */
/*** Tried 'seventh day of -1 month'
/* it gives 1970-01-01
*/
我要的是上个月的07
嗯....一个月的第一天总是01....所以基本上你只需要年份和月份:
$firstOfMonth = "2015-01-01";
$last_month = date("Y-m-01",strtotime("-1 month",strtotime($firstOfMonth)));
就像Mr.Manhattan说的,你只需要年月和第七天,你可以把它硬编码或放在一个变量中:
date("Y-m-07",strtotime("-1 month"));
$fixedDay = '07';
echo date("Y-m-$fixedDay",strtotime("-1 month"));
我试过了:
$firstOfMonth = "2015-01-01";
$last_month = date("Y-m-d", strtotime('first day of -1 month', strtotime($firstOfMonth)));
/* ^^^^^ This gives me 01 of last month */
/*** Tried 'seventh day of -1 month'
/* it gives 1970-01-01
*/
我要的是上个月的07
嗯....一个月的第一天总是01....所以基本上你只需要年份和月份:
$firstOfMonth = "2015-01-01";
$last_month = date("Y-m-01",strtotime("-1 month",strtotime($firstOfMonth)));
就像Mr.Manhattan说的,你只需要年月和第七天,你可以把它硬编码或放在一个变量中:
date("Y-m-07",strtotime("-1 month"));
$fixedDay = '07';
echo date("Y-m-$fixedDay",strtotime("-1 month"));