所以我有这个奇怪的问题,我不太明白。我只是想用两个日期时间来水合一个对象,“开始时间”和“结束时间”。我通过添加 DateInterval 获得结束时间(本例中为 3 天)
这是我的控制器
$datenow = new \DateTime('now');
var_dump($dateNow);
$relation->setDateAjout($dateNow);
$date = $dateNow;
$duration=(string)$flower->getDuration();
$dateEnd=$date->add(new \DateInterval('P'.$duration.'D'));
var_dump($dateEnd);
$relation->setDateFin($dateEnd);
$em = $this->getDoctrine()->getManager();
$em->persist($relation);
$em->flush();
二传手,看起来不错
/**
* Set dateAjout
*
* @param \DateTime $dateAjout
* @return Fleur
*/
public function setDateAjout($dateAjout)
{
$this->dateAjout = $dateAjout;
return $this;
}
/**
* Set dateFin
*
* @param \DateTime $dateFin
* @return Fleur
*/
public function setDateFin($dateFin)
{
$this->dateFin = $dateFin;
return $this;
}
什么 var 转储显示(酷)
object(DateTime)[368]
public 'date' => string '2014-10-02 12:41:17' (length=19)
public 'timezone_type' => int 3
public 'timezone' => string 'Europe/Paris' (length=12)
object(DateTime)[368]
public 'date' => string '2014-10-05 12:41:17' (length=19)
public 'timezone_type' => int 3
public 'timezone' => string 'Europe/Paris' (length=12)
phpmyadmin 结果(不酷)
2014-10-05 12:41:17
and
2014-10-05 12:41:17