简体   繁体   English

PHP strtotime 不求和

[英]Php strtotime not sum vaules

Hello i'm using this code to make a test.您好,我正在使用此代码进行测试。

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

But the output is '15:32:04' instead of '00:00:20' and i cannot find the solution.但是输出是“15:32:04”而不是“00:00:20”,我找不到解决方案。

I also try:我也尝试:

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

and give me the same output.并给我相同的输出。

Thanks for help感谢帮助

You should be using the dateTime class: http://php.net/manual/en/class.datetime.php您应该使用 dateTime 类: http : //php.net/manual/en/class.datetime.php

It's a lot simpler once you start using it and you can do almost anything you'd like by calling a function.一旦你开始使用它就简单多了,你几乎可以通过调用一个函数来做任何你想做的事情。 for example you can add X time to a date object by calling the add function: http://php.net/manual/en/datetime.add.php例如,您可以通过调用 add 函数将 X 时间添加到日期对象: http : //php.net/manual/en/datetime.add.php

Bear in mind this class will only exist for you if you have php 5.3 or higher.请记住,只有当您拥有 php 5.3 或更高版本时,这个类才会存在。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM