-1
$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 的值为 17:45,我每次获取 17:00

$start (true value = 13:30) 和 $end (true value = 17:45) 的 print_r :

DateTime 对象 ( [date] => 2013-08-12 13:30:00 [timezone_type] => 3 [timezone] => Europe/Berlin ) DateTime 对象 ( [date] => 2013-08-12 17:00: 00 [timezone_type] => 3 [timezone] => 欧洲/柏林)

第二个 DateTime 应该是 17:45 而不是 17:00

$arr_heures 的 print_r 是:

数组( [0] => 13:30 [1] => 17:45 )

PHP 日志向我显示了这个错误:

在第 64 行的 /Applications/MAMP/htdocs/imaginatiff/reservations/PHP/class/Calendrier.class.php 中遇到格式不正确的数值

第 64 行是$end->setTime($arr_heures[1], 0);

请问你有什么想法吗?谢谢你。

4

1 回答 1

0

您使用setTime不正确 - 小时和分钟应该是单独的参数。

正确的是:

list ($h, $m) = explode(':', $arr_heures[1]);
$end->setTime($h, $m); // you can omit seconds when zero

当某个功能不像您期望的那样工作时,阅读手册是一个好主意。

于 2013-08-12T18:37:39.983 回答