Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/tfs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 多个日期中的小时总数_Php_Symfony - Fatal编程技术网

Php 多个日期中的小时总数

Php 多个日期中的小时总数,php,symfony,Php,Symfony,我有一个小时的总数 foreach ($horaires as $horaire) { $addition += strtotime($horaire->getPointNbh()->format('H:m:s')); } 而且它不起作用。有人可以帮助我如何使用Symfony 2对DateTimne类型进行操作 感谢在Symfony或Datetime对象中没有解决方案,这是我的解决方案: $heure = 0; foreach ($horaires as

我有一个小时的总数

foreach ($horaires as $horaire) {

    $addition += strtotime($horaire->getPointNbh()->format('H:m:s'));

}
而且它不起作用。有人可以帮助我如何使用Symfony 2对DateTimne类型进行操作


感谢

在Symfony或Datetime对象中没有解决方案,这是我的解决方案:

    $heure = 0;
    foreach ($horaires as $horaire) {
        $heure += $horaire->getPointNbh()->format('H') *3600 + $horaire->getPointNbh()->format('i') *60 + $horaire->getPointNbh()->format('s');  ;
        //$heure = $heure * 3600;

    }
    $hour = floor($heure /3600);
    $min = floor($heure%3600/60);
    $sec = $heure - (($hour*3600) + ($min*60));
    $result = $hour.":".$min.":".$sec;

    return $result;

您是否尝试使用DateTime类方法来实现它?创建一个执行该求和的查询不是更容易吗?您是对的,但我确信这样做更容易,我想知道.strotime如何返回Unix时间戳。这真的是你想要的吗?你能描述一下getPointNbh是什么类型的吗?getPointNbh是一个日期时间,我试过不使用strotime也不工作!!我的问题是如何在php中对DateTime对象计算小时数