简体   繁体   中英

PHP 5.2.9 equivalent of this function

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');        

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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