1 回答
TA贡献1847条经验 获得超7个赞
为了设置今天的默认值,我construct在我的实体对象中使用该方法。
public function __construct()
{
$this->arrival = new \DateTimeImmutable();
$this->departure = \new \DateTimeImmutable();
}
Q1 的答案:为了删除秒,只需创建一个DateTime没有秒的新对象。
public function __construct()
{
$this->arrival = \DateTimeImmutable::createFromFormat('Y-m-d H:i', date('Y-m-d H:i'));
$this->departure = \DateTimeImmutable::createFromFormat('Y-m-d H:i', date('Y-m-d H:i'));
}
//$this->arrival = new \DateTimeImmutable(date('Y-m-d H:i')); //this also works, but needs execption handling (try/catch)
Q2的答案:此问题的答案相同 - 只需在实体中预设当前日期并使用TimeType让用户选择时间。
- 1 回答
- 0 关注
- 154 浏览
添加回答
举报
