首页 > 解决方案 > 回声新日期时间();在 wordpress 上导致严重错误

问题描述

如果我去我的 wordpress 网站

<?php $theCurrentDate = new DateTime(); ?>
<?php echo $theCurrentDate; ?>

它导致我的网站出现严重错误,为什么?

PHP DateTime 异常和错误处理

<?php 
  try   {
     $dt = new DateTime();
     echo $dt;
  } catch (Exception $e) {
     var_dump($e->getMessage());
  }
?>

我仍然在现场遇到严重错误。

这里发生了什么?当你在 php 中回显 datetime() 时怎么会破坏 wordpress?

标签: phpdatetime

解决方案


https://www.php.net/manual/en/datetime.format.php

显然你必须指定格式

<?php $theCurrentDate = new DateTime(); ?>
<?php echo $theCurrentDate->format('Y-m-d H:i:s'); ?>

推荐阅读