【问题标题】:Datetime format as string not object日期时间格式作为字符串而不是对象
【发布时间】:2019-09-07 10:50:16
【问题描述】:

我正在设置一个表格,我需要从表格发送之日起的下一个星期日,我在我的mealPrepSend.php 文件中有这个作为我的代码:

$deliveryDate = new DateTime(); 
$deliveryDate->modify('next sunday');
$deliveryDate->format('D d M H:i:s');

表单现在出现错误:

Recoverable fatal error: Object of class DateTime could not be converted to string in /deli/mealPrepSend.php on line 34

我做了一些阅读,发现它与输出的格式有关,非常欢迎任何帮助!

非常感谢,

【问题讨论】:

  • 第 34 行是哪一行?这甚至是指您上面显示的三个之一吗?
  • 我不确定您的错误来自哪里?您提供的代码应该可以正常工作,因为它可以很好地转换为字符串。以下以您请求的格式返回一个字符串:$deliveryDate = (new \DateTime('next sunday'))->format('D d M H:i:s');

标签: php forms


【解决方案1】:

您可以使用此代码 sn-p 代替您正在使用的代码

date('D d M H:i:s',strtotime('next sunday'));

你可以这样放静态小时

echo date('D d M H:i:s',strtotime('next sunday 09:00'));

【讨论】:

  • 感谢您的快速回复,效果很好。我怎么能把时间设置为 09:00 而不是 00:00 谢谢!
猜你喜欢
  • 1970-01-01
  • 2017-11-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-06-27
  • 1970-01-01
  • 1970-01-01
  • 2014-08-10
相关资源
最近更新 更多