时间减去PHP上的时间

时间减去PHP上的时间,php,laravel,time,Php,Laravel,Time,我有一个字符串时间$a=“17:20:00” 我想做什么 if($a > "13:00:00"){ $c = $a - "01:00:00"; } 我想获得$c=“16:20:00” 如何做到这一点? 谢谢大家! $a是一个字符串,不能这样比较。 用于设置为UNIX时间(整数)并减去3600秒。 然后使用转换回字符串 $a = strtotime("17:20:00"); if($a > strtotime("13:00:00")){ $c

我有一个字符串时间
$a=“17:20:00”
我想做什么

  if($a > "13:00:00"){
    $c = $a - "01:00:00";
  }
我想获得
$c=“16:20:00”
如何做到这一点?
谢谢大家!

$a是一个字符串,不能这样比较。
用于设置为UNIX时间(整数)并减去3600秒。
然后使用转换回字符串

$a = strtotime("17:20:00");
    if($a > strtotime("13:00:00")){
        $c = $a - 3600;
}

Echo date("H:i", $c);

$a是一个字符串,不能这样比较。
用于设置为UNIX时间(整数)并减去3600秒。
然后使用转换回字符串

$a = strtotime("17:20:00");
    if($a > strtotime("13:00:00")){
        $c = $a - 3600;
}

Echo date("H:i", $c);
您应该尝试以下方法:

if(strtotime($a) > strtotime("13:00:00")){
    $c = date( "h:i:s", strtotime($a) - strtotime("01:00:00")); 
  }
你应该试试这个

您应该尝试以下方法:

if(strtotime($a) > strtotime("13:00:00")){
    $c = date( "h:i:s", strtotime($a) - strtotime("01:00:00")); 
  }

你应该试试这个

好吧,试着用谷歌搜索一下,你会发现:你做过任何研究吗?检查此链接使用'strotime'函数进行减法运算。您需要使用
strotime()
转换字符串,然后从中减去时间。好吧,尝试一下谷歌搜索,您会发现:您做过任何研究吗?检查此链接使用'strotime'函数进行减法。您需要使用
strotime()
转换字符串,然后从中减去时间。请按照此操作。请按照此操作。谢谢!我已经解决了我的问题谢谢!我已经解决了我的问题