dotws86260
2015-01-19 22:58
浏览 55
已采纳

从PHP开始并保持这种格式减去PHP中的时间戳:00:00:00

I have 2 strings:

$time1 = '00:00:10';
$time2 = '00:00:04';

Using PHP, how can I subtract $time1 from $time2 so that I end up with:

$time3 = '00:00:06';

图片转代码服务由CSDN问答提供 功能建议

我有2个字符串:

  $ time1 = '00  :00:10'; 
 $ time2 = '00:00:04'; 
   
 
 

使用PHP,如何从$ time2中减去$ time1,以便 我最终得到:

  $ time3 = '00:00:06'; 
   
 
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doutu6658 2015-01-19 23:02
    已采纳

    Yes you can, but first you need to convert those timestamps to int format to be able to subtract them.

    $time1_timestamp = strtotime($time1);
    $time2_timestamp = strtotime($time2);
    
    $time3 = $time1_timestamp - $time2_timestamp;
    

    And then convert it back into hh:mm:ss format:

    $time3 = date('H:i:s', $time3);
    
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题