PHP将两个时间变量相加 [英] PHP add up two time variables

查看:69
本文介绍了PHP将两个时间变量相加的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的PHP应用程序中,我想计算两个时间变量的总和.我正在寻找类似此示例的内容.

In my PHP application I want to calculate the sum of two time variables. I am looking for something like this example.

$time1 = 15:20:00;
$time2 = 00:30:00;
$time = $time1+$time2;

推荐答案

做到这一点的最佳方法是最有可能使用strtotime将它们转换为时间戳,然后进行加法运算:

The best way to do this is most likely to use strtotime to convert them to timestamps and then do the adding together:

$o = strtotime($time1)+strtotime($time2);

如果我没记错的话,strtotime确实支持这种格式.

If I remember right strtotime does support this format.

否则,您需要自己将其过滤掉.

Otherwise you will need to filter it out yourself.

这篇关于PHP将两个时间变量相加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆