我试图用这个月的最后一天,以取代目前的一天,但错误返回调用成员函数的setDate()的字符串
调用成员函数的setDate()的字符串
在最后一行。除了功能的setDate
//current date which is 2017-08-28 10:50:30
$string = $date1;
$dateM = DateTime::createFromFormat("Y-m-d H:i:s", $string);
//getting the day of the month which is 28
$dateMonth = $dateM->format("d");
//if the day is 28
if($dateMonth >= 28){
//change the day to 31
$dateMonth = 31;
//current date which is 28/08/2017
$out = $date1;
//replace 28 with 31
$date1 = $out->setDate($out->format('Y'), $out->format('m'), $dateMonth , $out->format('H'), $out->format('i'), $out->format('s'));
}
是什么'$ date1'? – Neodan
看来$ date1是一个字符串,而不是日期文字。尝试使用$ dateM。 – jeff
第二行,''$ out-> setDate''-out是一个字符串,因此没有''setDate''函数。 – alistaircol