dongxia5394 2018-08-24 07:07
浏览 18
已采纳

php strtotime中遇到的一个非常好的数值[重复]

This question already has an answer here:

how to solve this error?

  $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>';
}

Notice: A non well formed numeric value encountered in D:\xamp\htdocs\timetest.php on line 19

Notice: A non well formed numeric value encountered in D:\xamp\htdocs\timetest.php on line 20 02-01-1970 - 02-01-1970

line 19:

$date1=strtotime($string, $next_travel_date); $date2= strtotime($string, $next_endDate);

</div>
  • 写回答

1条回答 默认 最新

  • du127953 2018-08-24 07:12
    关注

    As I understand, for adding some days or time in any date, strtotime takes first parameter as date string and some interval with it.

    So code should be :

    $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);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 phython如何实现以下功能?查找同一用户名的消费金额合并—
  • ¥15 孟德尔随机化怎样画共定位分析图
  • ¥18 模拟电路问题解答有偿速度
  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址