【发布时间】:2021-01-27 13:45:16
【问题描述】:
在我的 Symofny 项目中,我希望我的实体拥有 timestamp 字段。
/**
* @ORM\Column(type="datetime", nullable=false)
*/
private $timestamp;
/**
* @ORM\PreUpdate
* @throws \Exception
*/
public function setTimestamp()
{
$this->timestamp = new DateTime("now");
return $this;
}
我想以时间戳格式保存?我怎样才能做到这一点? 喜欢 // => 1387909800
我使用的是 Symfony 4.3 版本。
【问题讨论】:
-
为什么要将它保存为时间戳?如果需要时间戳,可以从
DateTime对象轻松获取。