Php strtotime 不是求和值

Php strtotime not sum vaules

您好,我正在使用此代码进行测试。

 <?php echo date("H:i:s", strtotime('00:00:10') + strtotime('00:00:10')); ?>

但是输出是“15:32:04”而不是“00:00:20”,我找不到解决方案。

我也试试:

<?php echo gmdate("H:i:s", strtotime('00:00:10') + strtotime('00:00:10')); ?>

并给我相同的输出。

感谢帮助

您应该使用日期时间 class: http://php.net/manual/en/class.datetime.php

一旦您开始使用它,它就简单多了,您几乎可以通过调用一个函数来做任何您想做的事情。例如,您可以通过调用 add 函数将 X 时间添加到日期对象: http://php.net/manual/en/datetime.add.php

请记住,如果您拥有 php 5.3 或更高版本,此 class 将只适用于您。