我的站点托管的服务器位于php5.12.14上,当我从php5.3运行datetime对象时出错
# DateTime::add — Adds an amount of days, months, years, hours, minutes and seconds to a DateTime object
$date = new DateTime($item_user['mem_updated']);
# add a day to the object
$date -> add(new DateInterval('P1D'));
错误,
Fatal error: Call to undefined method DateTime::add() in /homepages/xxx.php on line xx
所以,我寻找其他解决方案,而不是坚持php5.3的datetime对象。如何编写代码来替换上面的代码?
基本上,我有来自mysql数据库的日期和时间数据(例如-
2011-01-21 02:08:39
),我只需要在该日期/时间上添加1天或24小时,然后将其传递到下面的函数中,$time_togo = time_togo($date -> format('Y-m-d H:i:s'));
谢谢。
最佳答案
strotime会起作用的
$timestamp = strtotime($item_user['mem_updated']);
$time_togo = date("Y-m=d H:i:s", strtotime("+1 Day", $timestamp));
关于php - PHP:替换DateTime对象,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4764034/