如何解决这个错误?
$timeFirst = strtotime('2011-05-12 18:20:20');
$timeSecond = strtotime('2011-05-13 18:20:20');
$differenceInSeconds = $timeSecond - $timeFirst;
$hour=$differenceInSeconds/60/60;
$days=$hour/24;
$days=ceil($days);
$data=array();
for($i=1; $i<=7; $i++){
if($i==1){
$next_travel_date=date('d-m-Y',$timeFirst);
$next_endDate=date('d-m-Y',$timeSecond);
}else if($i>1){
$string=" + $days days";
$date1=strtotime($string, $next_travel_date);
$date2= strtotime($string, $next_endDate);
$next_travel_date=date('d-m-Y',$date1 );
$next_endDate=date('d-m-Y',$date2);
}
$data['travel_date']=$next_travel_date;
$data['end_date']=$next_endDate;
echo $data['travel_date'].' - '.$data['end_date'].'<br>';
}注意:在第19行的D:\xamp\htdocs\timetest.php中遇到一个格式不正确的数值
注意:在第20 02-01-1970 - 02-01-1970 -1970行的D:\xamp\htdocs\timetest.php中遇到一个格式不正确的数值。
第19行:
$date1=strtotime($string,$next_travel_date);$date2= strtotime($string,$next_endDate);
发布于 2018-08-24 07:12:45
据我所知,为了在任何日期中添加一些天或时间,strtotime使用第一个参数作为日期字符串,并使用它的某些间隔。
因此,代码应该是:
$string = " + $days days";
$date1 = strtotime($next_travel_date . $string);
$date2 = strtotime($next_endDate . $string);
$next_travel_date = date('d-m-Y', $date1);
$next_endDate = date('d-m-Y', $date2);https://stackoverflow.com/questions/51999167
复制相似问题