【问题标题】:Php check if digit time is greater than other digit timephp检查数字时间是否大于其他数字时间
【发布时间】:2017-01-04 15:33:33
【问题描述】:

我有一个数字时间数字数组(我从输入字段中获取它们)。

这里有几个例子:

00:00:10
00:03:00
01:20:00

我的问题是,如何检查一个数字时间是否大于另一个?

以下功能可达到

00:01:00

然后我得到一个错误。

$inputTimes = $request->input('times', []);

foreach ($inputTimes as $inputKey => $inputValue)
{
    $Input = new Input();
    $Input->input_start = $inputValue['input_start'];

    $tInput     = explode(':', $inputValue['input_timelapse']);
    $implInput  = implode('', $tInput);
    $iImplInput = (int)$implInput;

    // Check if time is greater
    if($iImplInput > $iVideoDuration)
    {
    .. error time greater
    }
}

【问题讨论】:

  • 分 - 60 秒,小时 - 3600 秒。
  • @u_mulder 所以你建议将数字时间转换为秒?

标签: php time foreach explode implode


【解决方案1】:

我会使用 inbuild strtotime() 函数将其转换为 Unix 时间。

例如: strtotime('01:20:00'); 将输出 1483492800strtotime('00:01:00'); 将输出 1483488060

希望这会有所帮助。

【讨论】:

  • 谢谢,我会尽快尝试,你认为这也适用于这样的时间:0:01:00.003290?
  • 没有。 Unix 时间使用整秒。祝你好运 - 如果它解决了您的问题,请务必接受我的回答。
猜你喜欢
  • 1970-01-01
  • 2023-01-30
  • 1970-01-01
  • 1970-01-01
  • 2021-06-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-01-18
相关资源
最近更新 更多