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对象计算小时数