PHP 5.2.9 相当于此函数
我在 php 中有这段代码,但无法在 PHP 5.2.9 中运行 请给我一个想法来转换此代码以在 PHP 5.2.9 上工作 谢谢,
$startTime = new DateTime(date('h:i:s a'));
$endTime = new DateTime("3:00:00 pm");
$timeTaken = $endTime->diff($startTime);
$timeTaken = $timeTaken->format('%h hour, %i mins, %s sec');
I have this code in php that I could not run in PHP 5.2.9
please give me an Idea to convert this code to work on PHP 5.2.9
Thanks,
$startTime = new DateTime(date('h:i:s a'));
$endTime = new DateTime("3:00:00 pm");
$timeTaken = $endTime->diff($startTime);
$timeTaken = $timeTaken->format('%h hour, %i mins, %s sec');
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
PHP 5.2 中没有与
date->diff
等效的内置函数,因此您必须编写自己的函数。幸运的是,PHP 手册有注释,人们已经为您完成了艰苦的工作。
请参阅http://php.net/manual/en/function.date-diff。 php,向下滚动到评论,然后选择您最喜欢的解决方案(有多个可供选择)。
另一个解决方案就是硬着头皮升级——不再支持 PHP 5.2,因此您确实应该考虑升级。
There isn't a built-in equivalent for
date->diff
in PHP 5.2, so you'll have to write your own.Fortunately, the PHP manual has comments where people have done the hard work for you.
See http://php.net/manual/en/function.date-diff.php, scroll down to the comments, and pick your favourite solution (there are several to choose from).
The other solution is simply to bite the bullet and upgrade -- PHP 5.2 is no longer supported, so you really should be considering upgrading.