这个算strtotime("+1 month")的bug吗?
aiur 2007-10-10 02:22:32 我想写一个函数,返回传入日期的当月第一天和最后一天
$time = strtotime($init_date);
$year_temp = strftime("%Y",$time);
$month_temp = strftime("%m", $time);
//本月第一天
$start_date = date("Y-m-d",mktime(0,0,0,$month_temp,1,$year_temp));
$time = strtotime("+1 month",strtotime($init_date));
$year_temp = strftime("%Y",$time);
$month_temp = strftime("%m", $time);
$start_date1= mktime(0,0,0,$month_temp,1,$year_temp);
//通过下一个月的前一天,返回本月最后一天
$end_date = date("Y-m-d",strtotime("-1 day",$start_date1));
可是在测试的时候发现,如果传入$init_date = 1、3、5、8、10月的31号的时候,返回本月最后一天却是下一个月的最后一天!
比如传入2007-10-31,返回的是2007-11-30!
我看了下,主要原因可能是:这些月份的最后一天是31号,比下个月的最大天数都要大,在strtotime("+1 month")的时候,这个函数的返回值就跨越了两个月,而不是一个月!
请问各位,这个有什么解决的方法?或者是有什么好的方法得到本月的最后一天?谢谢!