php - $date =旧 PHP 版本的新日期时间

标签 php time

使用下面的代码我收到一个错误,我发现它与我的服务器没有运行最新的 PHP 有关:

$date = new DateTime('2000-01-01');
$date->add(new DateInterval('PT'.$a->metrics->duration.'S'));

错误: fatal error :调用未定义的方法 DateTime::add()

问题: 对于运行 PHP 5.2.17 的服务器,如何实现上述目标?

最佳答案

您可以使用 strtotime():

$date = strtotime ("2000-01-01");
$date = strtotime ("+900 seconds", $date); // adds 900 seconds to date

关于php - $date =旧 PHP 版本的新日期时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11826893/

相关文章:

php - LIKE 子句在 wordpress 的 $wpdb->prepare() 中不起作用

php - yii2 hasOne 关系工作错误

javascript - currentTime是否落在18 :00 and 2:00之间

php - Google 通过 XML 自定义站点搜索...如何获取 "did you mean..."值?

php - Magento 报告安装错误 : "Database server does not support the InnoDB storage engine"

php - SQL-Server 'uniqueidentifier' 列类型到 MySQL 的迁移问题

MySQL 时间数学

go - 在结构中表示可选 time.Time 的惯用方式

mysql - 如何正确地将mysql中的时区更新为东部时间?

date - 在 SQLite 中操作日期时间