【发布时间】:2016-03-07 10:31:59
【问题描述】:
您好,我正在使用此代码进行测试。
<?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')); ?>
给我同样的输出。
感谢您的帮助
【问题讨论】:
-
echo date("H:i:s", strtotime('00:00:10 + 10 seconds')); -
strtotime() 创建一个时间戳值(自 1970 年 1 月 1 日 00:00:00 UTC 以来的秒数),如果您不指定日期,则默认为当前日期,(今天)给出
1457305210为strtotime('00:00:10')(即2016-03-07 00:00:10);所以你不能简单地将这些时间戳加在一起,除非你强制日期为 Jan 01 1970 -
strtotime返回一个时间戳。添加 2 个时间戳意味着您不仅要添加秒数,还要添加年数。