在 php strtotime 中遇到格式不正确的数值
A non well formed numeric value encountered in php strtotime
如何解决这个错误?
$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 行 D:\xamp\htdocs\timetest.php 中遇到格式不正确的数值
02-01-1970 - 02-01-1970
第 19 行:
$date1=strtotime($string, $next_travel_date);
$date2= strtotime($string, $next_endDate);
据我所知,为了在任何日期中添加一些天数或时间,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);
如何解决这个错误?
$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 行 D:\xamp\htdocs\timetest.php 中遇到格式不正确的数值 02-01-1970 - 02-01-1970
第 19 行:
$date1=strtotime($string, $next_travel_date); $date2= strtotime($string, $next_endDate);
据我所知,为了在任何日期中添加一些天数或时间,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);