我尝试在数据库中存储日期:
$entity->setTimestamp(\DateTime::createFromFormat('d.m.Y', "2005-08-15T15:52:01+00:00"));
但是我收到错误消息:
传递给App \ Entity \ Documents :: setTimestamp()的参数1必须实现接口DateTimeInterface,给定布尔值,
我实体中的函数:
public function setTimestamp(\DateTimeInterface $timestamp): self {
$this->timestamp = $timestamp;
return $this;
}
您的格式和日期时间不正确。使用以下代码
$date_time = DateTime::createFromFormat('Y-m-d\TH:i:sP', "2005-08-15T15:52:01+00:00");
$entity->setTimestamp($date_time->format("d.m.Y"));
而且这将是简单的字符串。因此,请更改setTimestamp
功能。否则,您可以返回整个$date_time
。