如何在 php 中动态添加时间

How to add times dynamically in php

我正在获取 9:5500:13:51 等视频的持续时间。我想在 php

的循环中添加这些值

我试过了

    $t_duartion =0;
    foreach ($learn_detail->video_det as $video_det){
        $t_duartion += date("H:i:s",strtotime($video_det->duration));
    }

但是结果还没有出来。它不是 hh:mm:ss 格式。如何在 php.

中实现这些家伙

有什么 body 想法吗?

根据您的逻辑,您尝试添加 00:13:00 和 09:14:53 等 wrong.try this:

    foreach ($learn_detail->video_det as $video_det){
        $t_duartion += strtotime($video_det->duration);
    }
$t_duartion = date("H:i:s",$t_duartion);

首先以秒为单位将所有持续时间相加,然后使用 date()

示例:

$t_duartion = 0; // Typo in variable name btw.

foreach ( $learn_detail->video_det as $video_det ) {
    // Add duration of current video in seconds to total count.
    $t_duartion += strtotime( $video_det->duration );
}

// Convert total seconds to hh:mm:ss format.
$time = date( 'H:i:s', $t_duartion );