在 PHP 中添加时间 [英] Add time in PHP

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

问题描述

如何在 PHP 中添加给定的时间?

How can I add a given number of time in PHP?

以下是我想添加的三个时间变量:

Below is are three time variables I would like to add:

time1: "00:02:00"
time2: "00:15:00"
time3: "00:08:00"

这是我试图实现这一目标的方法:

This was my approach in attempting to achieve that:

echo date('h:i:s', strtotime('00:02:00') + strtotime('00:15:00') + strtotime('00:08:00'));

我的代码的结果是12:25:00,而预期的结果应该是00:25:00.

The result of my code is 12:25:00, while the expected result should have been 00:25:00.

我做错了什么,如何在 PHP 中有效地添加给定的时间变量?

What am I doing wrong and how can I add given time variables effectively in PHP?

推荐答案

h变成H.

h => 带前导零的 12 小时格式

h => 12-hour format of an hour with leading zeros

H => 带前导零的小时的 24 小时制

H => 24-hour format of an hour with leading zeros

试试

echo date('H:i:s', strtotime('00:02:00') + strtotime('00:15:00') + strtotime('00:08:00'));

参考

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

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