Php 设置时间返回错误的时间
如果$end的值为17:45,则每次17:00我都会获得 打印$start(真值=13:30)和$end(真值=17:45): DateTime对象([日期]=>2013-08-12 13:30:00[时区类型]=>3[时区]=>Europe/Berlin)DateTime对象([日期]=>2013-08-12 17:00:00[时区类型]=>3[时区]=>Europe/Berlin) 第二个日期时间应该是17:45,而不是17:00 $arr\u heures的打印格式为: 数组([0]=>13:30[1]=>17:45) PHP日志显示此错误: 第64行的/Applications/MAMP/htdocs/imaginiff/reservations/PHP/class/Calendrier.class.PHP中遇到格式不正确的数值 第64行是Php 设置时间返回错误的时间,php,Php,如果$end的值为17:45,则每次17:00我都会获得 打印$start(真值=13:30)和$end(真值=17:45): DateTime对象([日期]=>2013-08-12 13:30:00[时区类型]=>3[时区]=>Europe/Berlin)DateTime对象([日期]=>2013-08-12 17:00:00[时区类型]=>3[时区]=>Europe/Berlin) 第二个日期时间应该是17:45,而不是17:00 $arr\u heures的打印格式为: 数组([0]=>1
$end->setTime($arr\u heures[1],0)代码>
你有什么想法吗?谢谢。您使用不正确——小时和分钟应该是单独的参数
正确答案是:
$hours = array();
$heures = Configuration::renvoyer_heures_debut_fin();
$arr_heures = explode('#',$heures->heures_debut_fin);
$start = new \DateTime($arr_heures[0].':00');
$end = clone $start;
$end->setTime($arr_heures[1], 0);
当函数不能像您期望的那样工作时,阅读手册是一个好主意。测试了您的代码,它工作了,谢谢。我的也可以:$end=new\DateTime($arr_heures[1]。:00');
list ($h, $m) = explode(':', $arr_heures[1]);
$end->setTime($h, $m); // you can omit seconds when zero